svn commit: trunk/busybox: archival libbb
vda at busybox.net
vda at busybox.net
Fri Nov 24 14:55:23 UTC 2006
Author: vda
Date: 2006-11-24 06:55:23 -0800 (Fri, 24 Nov 2006)
New Revision: 16653
Log:
tar: cry murder and bail out if file shrinks under us while we tar it up
Modified:
trunk/busybox/archival/tar.c
trunk/busybox/libbb/copyfd.c
Changeset:
Modified: trunk/busybox/archival/tar.c
===================================================================
--- trunk/busybox/archival/tar.c 2006-11-24 14:54:27 UTC (rev 16652)
+++ trunk/busybox/archival/tar.c 2006-11-24 14:55:23 UTC (rev 16653)
@@ -59,7 +59,7 @@
typedef struct TarHeader TarHeader;
/*
-** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
+** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
** the only functions that deal with the HardLinkInfo structure.
** Even these functions use the xxxHardLinkInfo() functions.
*/
@@ -397,7 +397,17 @@
off_t readSize = 0;
/* write the file to the archive */
- readSize = bb_copyfd_eof(inputFileFd, tbInfo->tarFd);
+ readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
+ if (readSize != statbuf->st_size) {
+ /* 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", fileName);
+ }
+ /* Check that file did not grow in between? */
+ /* if (safe_read(inputFileFd,1) == 1) warn but continue? */
close(inputFileFd);
/* Pad the file up to the tar block size */
Modified: trunk/busybox/libbb/copyfd.c
===================================================================
--- trunk/busybox/libbb/copyfd.c 2006-11-24 14:54:27 UTC (rev 16652)
+++ trunk/busybox/libbb/copyfd.c 2006-11-24 14:55:23 UTC (rev 16653)
@@ -46,8 +46,7 @@
} else if (rd < 0) {
bb_perror_msg(bb_msg_read_error);
break;
- } else if (rd == 0) {
- /* All done. */
+ } else { /* eof - all done. */
status = 0;
break;
}
More information about the busybox-cvs
mailing list