mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
LZMA ZIP Extraction doesn't handle zero-byte files #97
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @leezer3 on GitHub (May 21, 2016).
When extracting all files in an archive, the LZMA extractor falls over when it encounters a zero-byte file.
This code will trigger it, assuming you've got a zero-byte file in the archive:
An exception is triggered here:
https://github.com/adamhathcock/sharpcompress/blob/master/SharpCompress/Compressor/LZMA/LzmaStream.cs#L219
Adding this simple check to the extraction process works around the problem:
Suggests to me that you're assuming a minimum size for the file, and attempting to read that far in the stream, even though all you should be reading is the header and skipping over?
@weltkante commented on GitHub (Jul 20, 2016):
@leezer3 Is this fixed? I made an archive with some files + an empty text file and it didn't trigger any exception, the empty text file unpacked fine along the other files.
@leezer3 commented on GitHub (Jul 20, 2016):
Nope, still throws a fit (Test.txt is zero-bytes, test.jpg is just a filler)
Test program:
Archive created:
test.zip
@leezer3 commented on GitHub (Jul 20, 2016):
Thought-
It's possible that the creator is actually at fault here?
I'll admit not having tested files created outside Sharpcompress, but I discounted it as they extracted fine with WinRAR.
@weltkante commented on GitHub (Jul 20, 2016):
Oh, interesting, I was testing with 7z archives (created with external application) and not zip archives since the title only said 'lzma'. Might take another look tomorrow but I'm more used to the internals of 7z/lzma than the zip version.
@leezer3 commented on GitHub (Jul 20, 2016):
Probably should have been a little clearer, so updated the title.....
Adding this at line 218 would appear to fix the issue:
https://github.com/adamhathcock/sharpcompress/blob/master/src/SharpCompress/Compressor/LZMA/LzmaStream.cs#L218
if(inputSize ==5) return total(A ZIP file header is 4 bytes long, so if our file is of zero length, the next file header will start at +5 bytes)
Don't know if that's just cosmetically hiding a deeper problem though.....
I don't really know enough about the structure of zip files to be happy making a change like this off my own bat though.