aboutsummaryrefslogtreecommitdiff
path: root/archival/tar.c
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-11-24 14:55:23 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-11-24 14:55:23 +0000
commit708d74b5fe4e29c55f76b79bc71aa6ae532d38fe (patch)
tree279f3ff5c1a47d36ad4eec248240f11c7ef8d438 /archival/tar.c
parent5d8a7711b9cf654949e1aea4ccf3ed47b7bfa478 (diff)
downloadbusybox-w32-708d74b5fe4e29c55f76b79bc71aa6ae532d38fe.tar.gz
busybox-w32-708d74b5fe4e29c55f76b79bc71aa6ae532d38fe.tar.bz2
busybox-w32-708d74b5fe4e29c55f76b79bc71aa6ae532d38fe.zip
tar: cry murder and bail out if file shrinks under us while we tar it up
git-svn-id: svn://busybox.net/trunk/busybox@16653 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'archival/tar.c')
-rw-r--r--archival/tar.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 6aaa42273..99c4adb6a 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -59,7 +59,7 @@ struct TarHeader { /* byte offset */
59typedef struct TarHeader TarHeader; 59typedef struct TarHeader TarHeader;
60 60
61/* 61/*
62** writeTarFile(), writeFileToTarball(), and writeTarHeader() are 62** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
63** the only functions that deal with the HardLinkInfo structure. 63** the only functions that deal with the HardLinkInfo structure.
64** Even these functions use the xxxHardLinkInfo() functions. 64** Even these functions use the xxxHardLinkInfo() functions.
65*/ 65*/
@@ -397,7 +397,17 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
397 off_t readSize = 0; 397 off_t readSize = 0;
398 398
399 /* write the file to the archive */ 399 /* write the file to the archive */
400 readSize = bb_copyfd_eof(inputFileFd, tbInfo->tarFd); 400 readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
401 if (readSize != statbuf->st_size) {
402 /* Deadly. We record size into header first, */
403 /* and then write out file. If file shrinks in between, */
404 /* tar will be corrupted. So bail out. */
405 /* NB: GNU tar 1.16 warns and pads with zeroes */
406 /* or even seeks back and updates header */
407 bb_error_msg_and_die("short read from %s", fileName);
408 }
409 /* Check that file did not grow in between? */
410 /* if (safe_read(inputFileFd,1) == 1) warn but continue? */
401 close(inputFileFd); 411 close(inputFileFd);
402 412
403 /* Pad the file up to the tar block size */ 413 /* Pad the file up to the tar block size */