Skip to content
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

Add more ZipArchive tests to confirm the Zip64 fix does not affect reading zip files generatd with the old bug #103152

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

carlossanlop
Copy link
Member

We recently fixed a bug in ZipArchive that prevented setting the zip64 bit corectly in the local header for very large files: #102053

This PR adds two more tests to confirm the above test works:

  • One OuterLoop test for .NET that creates a large zip file, manually sets the zip64 bit to the old value, then attempts to open the zip again with ZipArchive, to confirm it is indeed read without problems by ZipArchive after the fix.
  • A manual test split in two parts:
    • A .NET test that simply generates a large zip file with the zip64 fix.
    • A .NET Framework test that expects that large zip file in the TEMP folder, then confirms ZipArchive can read it without problems.

…y value, then confirms it can still be opened using the fixed ZipArchive code.
…ge zip archive with the zip64 fix, and another one that is run using .NET Framework which reads the buggy zip file and confirms it can be read without problems.
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.

using FileStream fs = File.OpenRead(zipArchivePath);

// Open archive to verify that we can still read an archive with the buggy version
using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
Copy link
Member

@ericstj ericstj Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug in NETFX was actually with the validation in System.IO.Packaging. So this would pass even with the broken zip.

I'm not sure there's value in having this test committed even if we made it for IO.Packaging, since it has manual steps.

Maybe there's some value in having some suite of compatibility tests that produce different zips / IO.Packaging packages on one framework, and then consume them on the other framework without intervention? Perhaps those could be done in a way that they are a theory based on a number of different scenarios? I don't see that as a necessary thing for this particular fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have prior art running two different test processes for different frameworks?

long currentPosition = fs.Position;

// Confirm it's initially set to the correct value
using (BinaryReader reader = new(fs, Encoding.UTF8, leaveOpen: true))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can open the reader and writer at the same time, and just move the position back 2 bytes after you read it. That makes this more reabable and should reduce the code a bit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is more important to be able to close the ZipArchive, dispose it, then reopen it from the same stream, and confirm that the ZipArchive can be opened, the ZipArchiveEntry can be created without unexpected errors, and finally confirm the zip64 value was unmodified.

If I reduce the code as suggested, that would mean using the exact same ZipArchive object, without really verifying that the ZipArchive and the ZipArchiveEntry instances could still be created successfully.


fs.Position = 0;

// Open archive to modify the bit as it used to look before fix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the source has a define for DEBUG_FORCE_ZIP64. I don't see us ever use that, but I imagine the idea was we could use reflection to set that field and it would make a smaller zip use Zip64. That might be an interesting method to test this without forcing things to outerloop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to keep it in mind. I wasn't aware that it could be used for testing. At the moment I felt that it was more important to confirm that the real life scenario is working. I'll consider using the define in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants