-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streams larger than uint.MaxValue
cause broken zip files
#209
Comments
Thanks for this. If you could implement zip64 writing that would be great! I imagine both of the solutions you mentioned will be required (unless changing to zip64 from zip can be automatic) I have to confess I haven't looked too deeply at the zip64 format at the moment. |
Urgh, I just found an error from this commit: The values here are changed:
But the write uses the type here:
So now it writes invalid local headers, as they have 8 byte sizes instead of 4 byte sizes.... |
Urgh, and in the central directory too! |
Wow that is a bad error. The writing needs to know if it's zip64 or not and write the correct byte size. I guess zip64 writing needs done asap. |
zip64 maintains the size, but sets it to |
Thanks for the quick merge and update. I will investigate some more, because there must be some mitigating factor, otherwise the filenames would be garbled in all produced zip files, and that would break my unittests, so I would have caught it there. |
If you've got some tests that can be added to SharpCompress, I would appreciate it. Thanks for finding this. Fixed by #210 |
This issue is not fixed, the #210 was a problem with writing invalid headers. |
Phew, found the mitigating factor:
This is still wrong, as it converts to 8 bytes, and then takes only 4. Fortunately little endian notation means that the value is written correctly on any x86 or ARM machine. |
Nope, wrong again, the actual entry used is:
Which has the |
You can't zip files larger than 4 GB. The Zip64 support is currently read only |
Sure you can, try the example code in this issue. |
If it works, then it's unintentional and you're finding the errors because of it. |
Yes, that is why I opened the issue. You can create a zip file larger than 4gb without errors, and you see the errors only when you try to read the file. I would expect some error to happen when crossing the 4gb limit, otherwise I will not discover the problem before I attempt to read the file. |
Okay, sorry. I thought this was a discussion of the continuation of the writing error. Yes, something should be done to know files are too large for zip and/or implement zip64 |
I have tracked down an issue causing failures when attempting to read zip files with SharpCompress (files created AND read by SharpCompress).
The error message is
Unknown header {value}
, where{value}
is some random bytes from the file. This is similar to issue #33, but they report it for a much smaller file (I have tested the file mentioned in the issue, and it does not appear to cause any errors).The problem is that the Central Directory Entry is limited to storing the
Size
andHeaderOffset
asuint
values.There are no checks in SharpCompress if this limit is exceeded, causing the creation to succeed, but then failing to read them later. In the example below, this is done with a single file of 4GB size, but it can also be achieved with many smaller files, as long as the
HeaderOffset
value becomes larger than2^32
.There is another issue in that the number of files are limited to
ushort
, but this appears to have no effects other than reporting the wrong number of files, which is not directly exposed.A workaround to reading such a file is using the forward-only interface, which does not read the Central Directory Entry, and this can correctly read the file contents unless there is a single file larger than
2^32
.I can think of two solutions:
Prevent creating files with offsets larger than
2^32
, simply throwing an exception if this is detected.Support zip64, which replaces the size and offset with
0xffffffff
and stores a 64bit value in the extended information.I think support for zip64 is the better choice here. Reading support for zip64 has already been added, but it requires that the correct zip64 records are written.
I will see if I can make a PR that adds zip64 support.
Example code that reproduces the issue:
The text was updated successfully, but these errors were encountered: