Hi,

$ dd of=sparsefile seek=4096 bs=1M count=0

$ tar -c --sparse --format=gnu -f sparsefile.gtar sparsefile
$ tar -x -f sparsefile.gtar -O sparsefile | cat >/dev/null
tar: sparsefile: Cannot seek to 4294967296: Invalid argument
tar: Error exit delayed from previous errors

$ tar -c --sparse --format=posix -f sparsefile.ptar sparsefile
$ tar -t -v -f sparsefile.ptar
-rw-rw-r-- eswierk/eswierk 4294967296 2006-03-14 13:22:30 sparsefile
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
$ tar -x -f sparsefile.ptar -O sparsefile | cat >/dev/null
tar: Unexpected EOF in archive
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now

If you repeat the above procedure with a smaller sparse file (1 MB
instead of 4096 MB), all the tar operations succeed.

Attached patch fix the first problem with gnu format.
--- tar-1.15.1/src/sparse.c.extractHugeSparse	2006-03-21 14:22:05.000000000 -0500
+++ tar-1.15.1/src/sparse.c	2006-03-21 14:23:27.000000000 -0500
@@ -47,7 +47,7 @@
 {
   int fd;                           /* File descriptor */
   bool seekable;                    /* Is fd seekable? */
-  size_t offset;                    /* Current offset in fd if seekable==false.
+  off_t offset;                    /* Current offset in fd if seekable==false.
 				       Otherwise unused */
   size_t dumped_size;               /* Number of bytes actually written
 				       to the archive */
@@ -59,7 +59,7 @@
 
 /* Dump zeros to file->fd until offset is reached. It is used instead of
    lseek if the output file is not seekable */
-static long
+static off_t
 dump_zeros (struct tar_sparse_file *file, off_t offset)
 {
   char buf[BLOCKSIZE];
@@ -76,8 +76,11 @@
       size_t size = offset - file->offset;
       size_t wrbytes;
       
-      if (size > sizeof buf)
-	size = sizeof buf;
+      if ( (offset - file->offset) > sizeof buf)
+        size = sizeof buf;
+      else
+        size = offset - file->offset;
+
       wrbytes = write (file->fd, buf, size);
       if (wrbytes <= 0)
 	{
_______________________________________________
Bug-tar mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-tar

Reply via email to