mafintosh / tar-stream

tar-stream is a streaming tar parser and generator.
MIT License
413 stars 93 forks source link

Error: Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped? #110

Closed palavrov closed 3 years ago

palavrov commented 4 years ago

https://github.com/mafintosh/tar-stream/blob/b737a8d5d24306ee14c46184fb2d34a862b08c79/extract.js#L180-L181

If header.size is modified for some reason in entry event handler causes this error. For now quick fix is just to avoid modifying the header.size in the event handler but at least it needs to be documented or even better to make and use a copy of the size in local variable.

PaulMcGuinness commented 3 years ago

I'm getting this error on certain tar file that unpacks perfectly fine using other tools, any thoughts? (I've zipped it up to attach it here) - The tar's come from a vxWorks platform if that helps?

backup_dbsave_cfg1sw4_11.0.2.82_20150609084847.tar.zip

palavrov commented 3 years ago

@PaulMcGuinness, the issue I got was caused by me modifying tar-stream header.size variable. If your code is modifying this variable too could be a good reason for this error message.

PaulMcGuinness commented 3 years ago

No, not doing any modifications. Using the simple example code. It's definitely tar version related (as newer versions of the same platform's backup work fine)

palavrov commented 3 years ago

So ... I debugged a bit and got the problem - your tar file fails the proper header checks ( look here if you are curious https://github.com/mafintosh/tar-stream/blob/e08fcd845744c43e1e71343f117be9993208103a/headers.js#L264 ).

Solution is to: 1) Conform with the expected tar file format. 2) Pass to extract({allowUnknownFormat:true}) 3) Do a PR here with a fix how to detect the header

I would suggest to go for 1

PaulMcGuinness commented 3 years ago

Many thanks for the solutions - I can't change the tar format, and (3) is outside my abilities, so I'll try (2) tomorrow :-)

PaulMcGuinness commented 3 years ago

Option (2) worked perfectly - Many thanks! :-)

mafintosh commented 3 years ago

If you wanna add a note about that to the readme send a PR 😊