diff options
author | Denis Vlasenko | 2006-12-22 00:21:07 +0000 |
---|---|---|
committer | Denis Vlasenko | 2006-12-22 00:21:07 +0000 |
commit | 714701c890b5f03253c5ecdb7367c4258ce78715 (patch) | |
tree | 7ddaf73cf2deda0f357b21802dab4d42798dd778 /archival/tar.c | |
parent | 0a8a7741795880201bcf78231d1eab0e2538bb0b (diff) | |
download | busybox-714701c890b5f03253c5ecdb7367c4258ce78715.zip busybox-714701c890b5f03253c5ecdb7367c4258ce78715.tar.gz |
tar et al: die if bb_copyfd_size copies less than asked for.
(we have bb_copyfd_exact_size now for that kind of usage)
Diffstat (limited to 'archival/tar.c')
-rw-r--r-- | archival/tar.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/archival/tar.c b/archival/tar.c index 7465e88..ee9007c 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -452,26 +452,28 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, /* If it was a regular file, write out the body */ if (inputFileFd >= 0) { - off_t readSize = 0; - - /* write the file to the archive */ - readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size); - /* readSize < 0 means that error was already reported */ - if (readSize != statbuf->st_size && readSize >= 0) { - /* Deadly. We record size into header first, */ - /* and then write out file. If file shrinks in between, */ - /* tar will be corrupted. So bail out. */ - /* NB: GNU tar 1.16 warns and pads with zeroes */ - /* or even seeks back and updates header */ - bb_error_msg_and_die("short read from %s, aborting", fileName); - } + size_t readSize; + /* Wwrite the file to the archive. */ + /* We record size into header first, */ + /* and then write out file. If file shrinks in between, */ + /* tar will be corrupted. So we don't allow for that. */ + /* NB: GNU tar 1.16 warns and pads with zeroes */ + /* or even seeks back and updates header */ + bb_copyfd_exact_size(inputFileFd, tbInfo->tarFd, statbuf->st_size); + ////off_t readSize; + ////readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size); + ////if (readSize != statbuf->st_size && readSize >= 0) { + //// bb_error_msg_and_die("short read from %s, aborting", fileName); + ////} + /* Check that file did not grow in between? */ - /* if (safe_read(inputFileFd,1) == 1) warn but continue? */ + /* if (safe_read(inputFileFd, 1) == 1) warn but continue? */ + close(inputFileFd); /* Pad the file up to the tar block size */ /* (a few tricks here in the name of code size) */ - readSize = (-(int)readSize) & (TAR_BLOCK_SIZE-1); + readSize = (-(int)statbuf->st_size) & (TAR_BLOCK_SIZE-1); memset(bb_common_bufsiz1, 0, readSize); xwrite(tbInfo->tarFd, bb_common_bufsiz1, readSize); } |