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

Set version in ZIP local header to ZIP64, when the file offset is >4GB #94970

Closed
wants to merge 5 commits into from

Conversation

karakasa
Copy link
Contributor

@karakasa karakasa commented Nov 19, 2023

Fix #94899. Analysis in the comments. This PR fixes some compatibility issues of ZIP64 archives with certain decompressors (such as .NET Framework).

The spec is unclear whether the versionNeeded should be same in the CD and LH, and decompressors like 7-Zip & Windows don't complain about the discrepancy. Nevertheless I found 7-Zip set the LH to version ZIP64 under such circumstance.

The test is put in the outer loop because it will create a large 5GB file.

ZipArchiveEntry didn't set ZIP64 in local
headers for small files if their offset are
>4GB.
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Nov 19, 2023
@ghost
Copy link

ghost commented Nov 19, 2023

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

Issue Details

Fix #94899. Analysis in the comments.

The spec is unclear whether the versionNeeded should be same in the CD and LH, and decompressors such as 7-Zip & Windows don't complain about the discrepancy. Nevertheless I found 7-Zip set the LH to version ZIP64 under such circumstance.

Author: karakasa
Assignees: -
Labels:

area-System.IO.Compression

Milestone: -

@karakasa karakasa changed the title Set version in ZIP local header to ZIP64, if the file offset is >4GB Set version in ZIP local header to ZIP64, when the file offset is >4GB Nov 19, 2023
@bryanhunwardsen
Copy link

Is there a line of sight to a resolution here?

@danmoseley
Copy link
Member

I think we thought we were waiting on @karakasa but I guess we're not. @carlossanlop does this change look reasonable to you - as you are best versed in the code/ the format?

@ericstj
Copy link
Member

ericstj commented Mar 18, 2024

@carlossanlop - can you please review this?

Copy link
Member

@carlossanlop carlossanlop left a comment

Choose a reason for hiding this comment

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

Thanks for your patience. Here's my review so far:

  • I see that setting the value of _offsetOfLocalHeader a few lines earlier in WriteLocalFileHeader is safe as it is only used in the new invocation of ShouldUseZIP64().
  • I can see the new ShouldUseZIP64() method has the right scope for this specific issue.
  • Left some suggestions for you to consider.

Please consider:

  • Addressing @danmoseley 's suggestion of adding a test case that uses compression.
  • Adding an extra test to System.IO.Packaging. We should test the original reported issue as close as possible. In the src/libraries/System.IO.Packaging/tests/Tests.cs file, there is a test called VeryLargePart, which can be used as inspiration for yours. Note that VeryLargePart is creating the zip file in-memory.
  • Can you please test that the generated zip file can be read with external zip tools like 7-zip, windows explorer, winzip, unzip, etc? Testing reading the generated zip file with external programming languages would also be great.

Once merged, we can backport it to any requested active servicing branches (8.0 or 6.0).

@danmoseley
Copy link
Member

@karakasa thanks for your patience. Do you expect to be able to continue with this PR, and address the feedback?

@karakasa
Copy link
Contributor Author

karakasa commented Apr 17, 2024

@carlossanlop

  • Addressing @danmoseley 's suggestion of adding a test case that uses compression.

Sure.

  • Adding an extra test to System.IO.Packaging. We should test the original reported issue as close as possible. In the src/libraries/System.IO.Packaging/tests/Tests.cs file, there is a test called VeryLargePart, which can be used as inspiration for yours. Note that VeryLargePart is creating the zip file in-memory.

May you elaborate how to achieve that? I believe the objective is essentially executing a single test, while the first part runs in the latest .NET and the second part runs in the .NET Framework. The VeryLargePart test you referenced doesn't address such problem.

  • Can you please test that the generated zip file can be read with external zip tools like 7-zip, windows explorer, winzip, unzip, etc? Testing reading the generated zip file with external programming languages would also be great.

I have tested. Is replying this PR with images sufficient?

@carlossanlop
Copy link
Member

I have tested. Is replying this PR with images sufficient?

Yes, absolutely. And thank you for doing that.

May you elaborate how to achieve that?

My suggestion is that you open src/libraries/System.IO.Packaging/tests/Tests.cs, duplicate the VeryLargePart, test, rename it, and then adjust it slightly to ensure it touches the code you're fixing. Let me know if you have additional questions.

@karakasa karakasa marked this pull request as draft May 5, 2024 15:54
@carlossanlop
Copy link
Member

@karakasa please let us know if you'll be able to continue looking into this. Otherwise, I can take over.

@carlossanlop carlossanlop added the needs-author-action An issue or pull request that requires more info or actions from the author. label May 9, 2024
@karakasa
Copy link
Contributor Author

karakasa commented May 9, 2024

@karakasa please let us know if you'll be able to continue looking into this. Otherwise, I can take over.

Go ahead. Apologize I don’t have resources recently.

@karakasa karakasa closed this May 9, 2024
@carlossanlop
Copy link
Member

No worries, @karakasa. Thanks anyway for helping move this along.

@karakasa karakasa deleted the issue-94899 branch May 25, 2024 08:45
@github-actions github-actions bot locked and limited conversation to collaborators Jun 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.IO.Compression community-contribution Indicates that the PR has been added by a community member needs-author-action An issue or pull request that requires more info or actions from the author.
Projects
None yet
6 participants