Bug 82878

Summary: A bunch of bugs in archive_read_data of libarchive
Product: Base System Reporter: Björn König <bkoenig>
Component: binAssignee: Tim Kientzle <kientzle>
Status: Closed FIXED    
Severity: Affects Only Me CC: kientzle
Priority: Normal    
Version: 5.4-RELEASE   
Hardware: Any   
OS: Any   

Description Björn König 2005-07-02 00:20:18 UTC

There is a bunch of bugs in the function archive_read_data of libarchive that prevents tar from working correctly in case you use the @filename statement of tar (see how-to-repeat section).

I refer to src/lib/libarchive/archive_read.c of HEAD:

line 367f: The return value is a size_t, therefore there is no point to return a code. Zero might be suitable or -1 to indicate an error.

line 371: This condition is always false, because if read_data_offset will be increased in the else branche then read_data_output_offset will be increased by the same value. There is no other point in the while loop where these variables will be changed -- nothing will be filled with zeros. Is this intended and for future purposes?

line 385: Always the beginning of the whole block will be copied. For example, if we have 8192 bytes at first and the whole block has a length of 10240 bytes then there are 2048 remaining bytes. The function returns and most likely it will be called twice to get the remaining bytes, but at this point memcpy would copy the wrong bytes - the first bytes of the block again.

line 395: same as 365f.

Fix: 

I tried to make a fix, but I had no success. It seems like that there are still more bugs than I enumerated.
How-To-Repeat: 

This small script demonstrates that archive_read_data doesn't work correctly. The diff command should return nothing.

--- schnipp ---
#!/bin/sh

test -f sys.tar || tar -cf sys.tar /usr/src/sys/i386
test -f newsys.tar && rm newsys.tar

tar -cf newsys.tar @sys.tar
tar -xf newsys.tar
diff -r usr/src/sys/i386 /usr/src/sys/i386
--- schnapp ---
Comment 1 Giorgos Keramidas freebsd_committer freebsd_triage 2005-07-02 13:18:06 UTC
Responsible Changed
From-To: freebsd-bugs->kientzle

Assign to our libarchive author.
Comment 2 Tim Kientzle freebsd_committer freebsd_triage 2005-09-10 19:46:36 UTC
State Changed
From-To: open->closed

Fix committed to -CURRENT.