std.zip: allow extraction of a wider range of zip files #24137
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sometimes you have to deal with ZIP files in the wild that, although they have some invalid metadata, actually decompress just fine.
Ultimately, it really depends on the ZIP file itself.
Here's an example:
test.zip
As you can see, there is some kind of mismatch with one of the filenames (I purposely corrupted the ZIP file slightly and renamed a file inside it called
zip.txt
tozip.tt
with some invalid byte between "t" and "t"), but it still extracts the files just fine and if you look inside the extracted files nothing is actually wrong.Now try the same with
std.zip
:However, when using the new option added in this PR:
It extracts it just fine! Just like
unzip
. It doesn't give the API user any warnings or anything to give to the end user though.Now you might suggest running
zip -F
or whatever but remember I'm talking about any kind of ZIP file there might be in the wild where it's not convenient to have to do something like that first. The point is to extract on a best-effort basis unless actually not possible (i.e. whenunzip
would report an error and abort instead of just printing a warning).So I guess what I'm saying is that
std.zip
should either have something like warnings just likeunzip
in this example and/or it should have some way to not immediately stop everything just because one little byte in the ZIP file doesn't match.The only workaround I can think of for this is commenting out the relevant
return error
s in my local copy of the standard library.So this PR attempts to fix this with a
best_effort
option.