mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-08 13:34:57 +00:00
Malformed zip file generated #521
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 @aboryczko on GitHub (May 26, 2022).
Hi,
I'm using salvois/LargeXlsx library for generating Excel files (which are essentialy zip files) that uses this library.
When I try to open a generated file in Excel it says that it's corrupt. If I try to open the file with any unzip tool there are no errors. When I use the built-in ZipArchive class from .NET Core everything works as expected.
I've dug a little deeper into the files generated by this library and the .NET one I see that every 16 kB I get 5 bytes inputed into the output stream.
I don't know if this is some special marker but Excel doesn't recognize it and it messes up the content for it i.e. instead of 's="0"' i have 's="0 ý€"'.
a simple way to reproduce it:
sequences are at offsets: 38, 32811, 65584,98357
Linking salvois/LargeXlsx#9
@Erior commented on GitHub (Jun 16, 2022):
I think you confuse CompressionType.None and CompressionType.Deflate , you will have extra information with CompressionType.Deflate, it is instructions for inflate to "copy the next 7fff bytes as is" and as said, it will repeat every 0x7fff
However, it is very uncommon to use DeflateCompressionLevel.None, many libraries limits you to atleast Level1 when you choose Deflate.
If you really do not want to compress, you usually choose CompressionType.None, if you want to use Deflate, it is better to choose Level1 as minimum.
@aboryczko commented on GitHub (Jun 17, 2022):
I doesn't matter which level I choose, the issue is the same Excel recognizes the file as corrupt. I've used none in the examples because it is easier to find which characters are causing the issue.
@Erior commented on GitHub (Jun 17, 2022):
Is there any tests in LargeXlsx when dumped to disk that shows the problem, could help me with understanding the problem/corruption, I guess right now I'm totally missing it.
@aboryczko commented on GitHub (Jun 17, 2022):
something in the lines of:
produces the malformed file.
@Erior commented on GitHub (Jun 17, 2022):
Thank you, that does make excel unhappy, I will investigate
@Erior commented on GitHub (Jun 17, 2022):
Did not find a corruption, however, we do explicitly say that the files are "Label"'s in this scenario , and that is obviously not right, removing it made Excel happy on my side. It would be great if you can test it out.
@aboryczko commented on GitHub (Jun 18, 2022):
@Erior sorry, I don't follow, could you explain a bit more how can I do it?
@Erior commented on GitHub (Jun 18, 2022):
Top of my head would be for you to build with the pull request changes and use that dll, or wait for @adamhathcock to accept the change and generate new release. Not sure if you can get binaries out from pull builds even though they are tested automatically.
Someone could build it for you and send dll's, that is however a matter of trust/security.
Perhaps Mr Hathcock knows of other options, I participate somewhat infrequently on github.
@adamhathcock commented on GitHub (Jun 20, 2022):
thanks for the fix @Erior
I'll push out the change soon as it was creating bad files.
@adamhathcock commented on GitHub (Jun 20, 2022):
https://www.nuget.org/packages/SharpCompress/0.32.1
@salvois commented on GitHub (Jul 11, 2022):
Hi @aboryczko , @Erior , @adamhathcock ,
SharpCompress 0.32.1 appears to fix the offending code posted above as per in salvois/LargeXlsx#9.
Many thanks for reporting and fixing this!
Salvo
@adamhathcock commented on GitHub (Jul 12, 2022):
🥳
@Nanook commented on GitHub (Jul 15, 2022):
I'm closing this issue after confirming it's now working.