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

Force write of local file header when "version needed to extract" changes #112032

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

Conversation

edwardneal
Copy link
Contributor

Contributes to #112017.

aapt2 creates ZIP entries with a "version needed to extract" of 0.0, but sometimes writes these entries with deflate compression (which requires a "version needed to extract" of 2.0.)

When a ZipArchive is opened in Update mode and a new item is added, the central directory is written with the correct value for this field. However, the local file header for existing entries isn't rewritten (because it hasn't changed.) This leads to a mismatch between the local file header values and the central directory header values, which causes Android app builds to fail.

When an existing entry's "version needed to extract" is changed, we force its local file header to be rewritten.

There's a test to cover this. I've also added an entry to the packaged_resources.zip file from the issue and confirmed that the field matches between the local file header and the CD header for all compressed entries in the resultant file.

@carlossanlop @jonathanpeppers

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 31, 2025
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.

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 the fix, @edwardneal! Left some nit comments and a non blocking question, but otherwise the fix LGTM.

aapt2 creates ZIP entries with a "version needed to extract" of 0.0, but sometimes writes these entries with deflate compression (which requires a "version needed to extract" of 2.0.)

This sentence in the description makes it sound like the bug is in aapt2. My understanding from your explanation in the original issue was that this is a bug in ZipArchive. Or is it a bug in both?

@carlossanlop
Copy link
Member

/azp run runtime-libraries-coreclr outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@filipnavara
Copy link
Member

My understanding from your explanation in the original issue was that this is a bug in ZipArchive. Or is it a bug in both?

My understanding is that the bug is in both. AAPT2 uses the Deflate algorithm and doesn't correctly set the "version to extract" field. ZipArchive corrects the "version to extract" to a valid value and updates the central directory, but fails to update the locally prefixed header for the corrected entries.

Adding/correcting comments in test, and slightly reducing the diff in ZipArchiveEntry.
@edwardneal
Copy link
Contributor Author

edwardneal commented Jan 31, 2025

Thanks @carlossanlop, I've addressed your review comments.

This sentence in the description makes it sound like the bug is in aapt2. My understanding from your explanation in the original issue was that this is a bug in ZipArchive. Or is it a bug in both?

filipnavara is correct, it's a bug in both. The ZIP file being generated in aapt2 is malformed, but ZipArchive has a bug because it's correcting the central directory header without doing the same for the local file header.

@carlossanlop
Copy link
Member

Lot's of unrelated failures. We rollbacked some helix machine updates due to reported generalized failures. I'll update the branch so the CI runs again.

@carlossanlop
Copy link
Member

/azp run runtime-libraries-coreclr outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

jonathanpeppers added a commit to dotnet/android that referenced this pull request Feb 3, 2025
Changes: dotnet/sdk@aca4b81...d6bc791
Changes: dotnet/runtime@6c58f79...e51af40

Updates:

* Microsoft.NET.Sdk: from 10.0.100-alpha.1.25069.2 to 10.0.100-preview.2.25102.3
* Microsoft.NETCore.App.Ref: from 10.0.0-alpha.1.25067.10 to 10.0.0-preview.2.25101.4
* Microsoft.NET.ILLink.Tasks: from 10.0.0-alpha.1.25067.10 to 10.0.0-preview.2.25101.4

Other changes:

Context: dotnet/runtime#112017
Context: dotnet/runtime#112032

* Default to `$(_AndroidUseLibZipSharp)=true` to temporarily workaround
a `System.IO.Compression.ZipArchive` issue.

In a future PR, we'll revert this change to use System.IO.Compression where
appropriate.

Co-authored-by: Jonathan Peppers <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.IO.Compression community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants