bug-tar
[Top][All Lists]
Advanced

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

Re: [Bug-tar] tar creates invalid archives when files shrink during read


From: Frank Heckenbach
Subject: Re: [Bug-tar] tar creates invalid archives when files shrink during reading
Date: Thu, 12 May 2005 00:35:21 +0200
User-agent: semail 20050409

> Frank Heckenbach <address@hidden> wrote:
> 
> > It's a bit hard to reproduce. This code reproduces a
> > problem rather reliably on my system:
> 
> Thanks.
> 
> > AFAICS, if you do it your way, you also need to move the
> 
> Sure, actually I meant the following:
> 
> Index: src/create.c
> ===================================================================
> RCS file: /cvsroot/tar/tar/src/create.c,v
> retrieving revision 1.94
> diff -p -u -r1.94 create.c
> --- src/create.c      7 Apr 2005 17:27:07 -0000       1.94
> +++ src/create.c      11 May 2005 08:44:08 -0000
> @@ -886,8 +886,6 @@ dump_regular_file (int fd, struct tar_st
>       }
>        size_left -= count;
>  
> -      set_next_block_after (blk + (bufsize - 1) / BLOCKSIZE);
> -
>        if (count != bufsize)
>       {
>         char buf[UINTMAX_STRSIZE_BOUND];
> @@ -900,9 +898,11 @@ dump_regular_file (int fd, struct tar_st
>                STRINGIFY_BIGINT (size_left, buf)));
>         if (! ignore_failed_read_option)
>           exit_status = TAREXIT_FAILURE;
> -       pad_archive (size_left);
> +       pad_archive (size_left + count);
>         return dump_status_short;
>       }
> +
> +      set_next_block_after (blk + (bufsize - 1) / BLOCKSIZE);
>      }
>    return dump_status_ok;
>  }
> 
> 
> (decrementing size_left after the conditional will produce incorrect
> warning messages).

I see. It seems to work now as far as it doesn't create invalid
archives. However, AFAICS it doesn't write the last (partial) block
read, but writes zeros instead. This should demonstrate it:

#!/bin/sh
rm -f foo bar
echo dummy > baz
dd if=/dev/urandom of=foo bs=1k seek=499994 count=2
(sleep 4; dd if=/dev/null of=foo bs=1k seek=499995 count=0) &
src/tar cf bar foo baz
src/tar tf bar

foo should still contain 1k random bytes, but in the archive created
it contains only zeros.

I think my original patch was closer to getting this right -- though
one might have to make sure the remaining space is filled with
zeros, and to correct size_left in the message.

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]