diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-22 00:21:07 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-22 00:21:07 +0000 |
commit | 714701c890b5f03253c5ecdb7367c4258ce78715 (patch) | |
tree | 7ddaf73cf2deda0f357b21802dab4d42798dd778 /archival/tar.c | |
parent | 0a8a7741795880201bcf78231d1eab0e2538bb0b (diff) | |
download | busybox-w32-714701c890b5f03253c5ecdb7367c4258ce78715.tar.gz busybox-w32-714701c890b5f03253c5ecdb7367c4258ce78715.tar.bz2 busybox-w32-714701c890b5f03253c5ecdb7367c4258ce78715.zip |
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 7465e881b..ee9007c47 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -452,26 +452,28 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, | |||
452 | 452 | ||
453 | /* If it was a regular file, write out the body */ | 453 | /* If it was a regular file, write out the body */ |
454 | if (inputFileFd >= 0) { | 454 | if (inputFileFd >= 0) { |
455 | off_t readSize = 0; | 455 | size_t readSize; |
456 | 456 | /* Wwrite the file to the archive. */ | |
457 | /* write the file to the archive */ | 457 | /* We record size into header first, */ |
458 | readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size); | 458 | /* and then write out file. If file shrinks in between, */ |
459 | /* readSize < 0 means that error was already reported */ | 459 | /* tar will be corrupted. So we don't allow for that. */ |
460 | if (readSize != statbuf->st_size && readSize >= 0) { | 460 | /* NB: GNU tar 1.16 warns and pads with zeroes */ |
461 | /* Deadly. We record size into header first, */ | 461 | /* or even seeks back and updates header */ |
462 | /* and then write out file. If file shrinks in between, */ | 462 | bb_copyfd_exact_size(inputFileFd, tbInfo->tarFd, statbuf->st_size); |
463 | /* tar will be corrupted. So bail out. */ | 463 | ////off_t readSize; |
464 | /* NB: GNU tar 1.16 warns and pads with zeroes */ | 464 | ////readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size); |
465 | /* or even seeks back and updates header */ | 465 | ////if (readSize != statbuf->st_size && readSize >= 0) { |
466 | bb_error_msg_and_die("short read from %s, aborting", fileName); | 466 | //// bb_error_msg_and_die("short read from %s, aborting", fileName); |
467 | } | 467 | ////} |
468 | |||
468 | /* Check that file did not grow in between? */ | 469 | /* Check that file did not grow in between? */ |
469 | /* if (safe_read(inputFileFd,1) == 1) warn but continue? */ | 470 | /* if (safe_read(inputFileFd, 1) == 1) warn but continue? */ |
471 | |||
470 | close(inputFileFd); | 472 | close(inputFileFd); |
471 | 473 | ||
472 | /* Pad the file up to the tar block size */ | 474 | /* Pad the file up to the tar block size */ |
473 | /* (a few tricks here in the name of code size) */ | 475 | /* (a few tricks here in the name of code size) */ |
474 | readSize = (-(int)readSize) & (TAR_BLOCK_SIZE-1); | 476 | readSize = (-(int)statbuf->st_size) & (TAR_BLOCK_SIZE-1); |
475 | memset(bb_common_bufsiz1, 0, readSize); | 477 | memset(bb_common_bufsiz1, 0, readSize); |
476 | xwrite(tbInfo->tarFd, bb_common_bufsiz1, readSize); | 478 | xwrite(tbInfo->tarFd, bb_common_bufsiz1, readSize); |
477 | } | 479 | } |