ali

BusyBox tar oddity

In Uncategorized on April 23, 2010 at 8:22 pm

Some versions of BusyBox tar will refuse to extract tar archives created with newer versions of GNU tar.

I tested with BusyBox v0.61.pre (2002.09.06-11:28+0000), but the problem may be present in newer versions of BusyBox. BusyBox v1.2.2 (2007.03.07-20:42+0000) doesn’t exhibit the problem.

Symptoms

tar will appear to extract the file, but won’t actually:

# tar xvf payload.tar
./payload
# ls -al payload
ls: payload: No such file or directory

Detective work

I created a file test_file and used it to create tar archives on different hosts.

I created the archive oldgnu.tar on the host rhel4a

wf@rhel4a ~$ tar --version
tar (GNU tar) 1.14
tar --format oldgnu -cvf oldgnu.tar test_file

I created the archive oldgnu2.tar on the host rhel5a

wf@rhel5a ~$ tar --version
tar (GNU tar) 1.15.1
tar --format oldgnu -cvf oldgnu2.tar test_file

Contents of oldgnu.tar (created on rhel4a)

wf@rhel5a ~/tmp/tar$ hexdump -c oldgnu.tar
0000000   t   e   s   t   _   f   i   l   e
0000010
*
0000060           0   1   0   0   6   6   4     0   0   0   2
0000070   0   0   0     0   0   0   2   0   0   0     0   0   0   0

Contents of oldgnu2.tar (created on rhel5a)

wf@rhel5a ~/tmp/tar$ hexdump -c oldgnu2.tar
0000000   t   e   s   t   _   f   i   l   e
0000010
*
0000060           0   0   0   0   6   4   4     0   0   0   2
0000070   0   0   0     0   0   0   2   0   0   0     0   0   0   0

Diagnosis

The difference is the extra 1 found on the line beginning at 0x60:

0000060           0   >1<   0   0   6   6   4     0   0   0
Host Tar Has 1? Extractable?
rhel5a 1.15.1 No No
rhel4a 1.14 Yes Yes

If I pass the —format=oldgnu to the tar on rhel5a, no extra 1 is added. This only happens on rhel4a.

Workaround

I’ve updated internal scripts script take the path to tar and gzip as options, and the callers can use known good binaries:

--tar=TAR             Path to the host 'tar' program
--gzip=GZIP           Path to the host 'gzip' program
--oldgnu              Pass the --format=oldgnu option to tar
--checkoldgnu         Check that tar creates 'oldgnu' compatible archives
Advertisements
%d bloggers like this: