I have extracted a large (3.9GB) tar.bz2 file using the following command:

tar -xjvf archive.tar.bz2

The extract proceeds fines but exits printing:

bzip2: (stdin): trailing garbage after EOF ignored

Is there a problem with the archive/extract? Has the integrity of my data been compromised?

  • bzip2 -tv archive.tar.bz2 returns 'ok'. – avanwyk Sep 30 '14 at 19:35
  • Running bunzip2 archive.tar.bz2 produces a tar, but also exits with bunzip2: trailing garbage after EOF ignored – avanwyk Sep 30 '14 at 19:54

trailing garbage means there is extraneous data at the end of the file that is not part of the bz2 format; so bz2 can't make any sense of the additional data (hence garbage).

If you want to provoke the error:

$ echo Hello World | bzip2 > helloworld.bz2
$ echo Something not bzip2... >> helloworld.bz2
$ bunzip2 < helloworld.bz2
Hello World

bunzip2: (stdin): trailing garbage after EOF ignored

The first command creates a valid bzip2 file that contains the message Hello World.

The second command appends Something not bzip2... to the bzip2 file. This is trailing garbage because it's not bzip2 compressed.

Running that through bunzip2 produces the valid data, but prints a warning about the extraneous, ignored data.

In the end, the data that was originally compressed is still intact, but something odd happened at the end of the file. It may be worth looking at it in a hex editor; sometimes you can tell what happened, sometimes you can't.

$ hexdump -C helloworld.bz2 
00000000  42 5a 68 39 31 41 59 26  53 59 d8 72 01 2f 00 00  |BZh91AY&SY.r./..|
00000010  01 57 80 00 10 40 00 00  40 00 80 06 04 90 00 20  |.W...@..@...... |
00000020  00 22 06 86 d4 20 c9 88  c7 69 e8 28 1f 8b b9 22  |."... ...i.(..."|
00000030  9c 28 48 6c 39 00 97 80  53 6f 6d 65 74 68 69 6e  |.(Hl9...Somethin|
00000040  67 20 6e 6f 74 20 62 7a  69 70 32 2e 2e 2e 0a     |g not bzip2....|

This example is obvious, since you usually do not see plain text like this in bzip2 compressed data.

The big question is whether the garbage was appended (like in the example above, leaving the original data intact), or if some kind of corruption happened. It's impossible to tell from the error message (bzip2 itself does not really know); however if it was a random corruption, you'd usually see some tar error messages too.

  • Thanks for the detailed explanation. I will try to have a look with a hex editor. I am hoping it's just some randomly appended data. – avanwyk Oct 1 '14 at 10:51

If you know the exact compression options for the file (probably just defaults), you could get the actual trailing data:

To get the size of the real compressed tar archive, recompress it.

Using the size of the file you get - which should be smaller than the size of your original file (maybe by just one byte) get the part after the real data:

tail -c +12345 witTrailingData.tar.bz2

(This may be dificult with the large file)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.