bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-tar] tar creates invalid archives when files shrink during reading


From: Frank Heckenbach
Subject: [Bug-tar] tar creates invalid archives when files shrink during reading
Date: Sat, 7 May 2005 05:36:45 +0200
User-agent: semail 20050409

tar 1.15.1 creates invalid archives when files shrink during
reading. The data records in the tar file contain more padding 0's
than necessary to fill up to the size stored. This renders the
archive invalid (`tar tf' stops at the first such file).

A "test case" is archiving files from the sysfs pseudo file system
in Linux 2.6 (usually mounted on /sys). This may make the bug
particularly serious, since when creating a complete system backup
via tar, and neglecting to exclude /sys when upgrading to Linux 2.6
(as /sys didn't exist before), the system backup gets invalid (which
is what happened to me -- though I could fix it by finding removing
those extra 0 records automatically).

The pseudo files in /sys report a size of 4096 on stat(), but the
actual data read are usually shorter. This is unlike prior kernels
which had those pseudo files in /proc with a stat() size of 0.
Whether the new behaviour is better or worse is another question
which I'm not really informed enough to discuss. Anyway, tar should
be able to handle this situation which can occur with regular files
being modified as well.

The following patch seems to fix the problem since `bufsize', not
`count' is used in the following `set_next_block_after' call.
(Though I must say that I found the code a bit confusing, so I'm not
sure I understood things correctly.)

--- tar-1.15.1/src/create.c.orig        Thu May  5 05:31:23 2005
+++ tar-1.15.1/src/create.c     Thu May  5 21:44:56 2005
@@ -872,7 +872,7 @@
           pad_archive (size_left);
           return dump_status_short;
         }
-      size_left -= count;
+      size_left -= bufsize;
 
       set_next_block_after (blk + (bufsize - 1) / BLOCKSIZE);
 

Frank

-- 
Frank Heckenbach, address@hidden
http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]