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

Read StartDiskNumber as uint32 #83923

Merged
merged 1 commit into from Jun 1, 2023
Merged

Conversation

mruslan97
Copy link
Contributor

  • The startDiskNumber field has been changed according to the zip specification.
  • Added test with the archive where the value of startDiskNumber greater than int.MaxValue.

Fix #31825

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Mar 25, 2023
@ghost
Copy link

ghost commented Mar 25, 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
  • The startDiskNumber field has been changed according to the zip specification.
  • Added test with the archive where the value of startDiskNumber greater than int.MaxValue.

Fix #31825

Author: mruslan97
Assignees: -
Labels:

area-System.IO.Compression

Milestone: -

Copy link
Member

@danmoseley danmoseley left a comment

Choose a reason for hiding this comment

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

looks good to me except couple things

@@ -1000,5 +1015,154 @@ public void ReadArchive_WithUnexpectedZip64ExtraFieldSizeUncompressedSizeIn32Bit
// comment length
0x00, 0x00
};

private static readonly byte[] s_zip64WithBigStartDiskNumber =
Copy link
Member

Choose a reason for hiding this comment

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

Rather than duplicate this whole thing what about just flipping the byte you need, within the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, i'll try. But I changed quite a few bytes in different parts(https://www.diffchecker.com/YK5V7XvS), so any advice would be helpful for me how to do it better

Copy link
Member

Choose a reason for hiding this comment

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

I almost wonder then whether it would make sense to extract that "proto zip" data into a mock with a method like SetStartDiskNumber. That would make it cleaner to use and easier to maintain and extend.
It could in future eg abstract the ability to add more entries, which is more than just flipping some bytes, and maybe in future expose ways to get the bytes corrupted in interesting ways, without the tests knowing about the structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I understand your idea correctly. We take s_slightlyIncorrectZip64 as a basis and create extensions for it such as SetStartDiskNumber? (and smth like SetCustomHeaderField in future)

Copy link
Member

Choose a reason for hiding this comment

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

yes -- I mean, I created that for a particular test and I see it's getting used in another place, now you needed it here and had to make larger edits as you say. But those tests shouldn't need to know the zip format.

So I wonder whether that suggests it would be helpful to wrap the array in a class that exposes it and that class can take care of any modifications a test needs. For now if nothing else you could just paste your new array in there, alongside the other one, but it would be a start.

If you don't want to do that here, I think what you have is fine. (I'll let area owners sign off though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I don't have an idea for a good implementation of this right now. It is complicated by the fact that different tests use different initialization methods (zip files in ZipTestData, byte arrays through MemberData or static byte arrays)

In my vision, it would look something like this:

var zipFile = FluentZipFileGenerator.CreateBuilder()
		.GetDefaultZipTemplate()
		.SetZip64ExtraFieldSize(args)
		.SetStartDiskNumber(args)
		.GenerateZipFile();

In this PR I can move the archive to ZipTestData/StrangeZipFiles folder.

Copy link
Member

Choose a reason for hiding this comment

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

@dotnet/area-system-io-compression would have to say what they would like. I don't have any strong opinion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should tag someone else?

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

https://github.com/orgs/dotnet/teams/area-system-io-compression would have to say what they would like. I don't have any strong opinion

As an ex-owner who is trying to review all stale PRs I think the PR is acceptable in the current state.

I like the concept of a builder than @mruslan97 proposed, but it can be a separate PR (let's don't block the fix anymore).

@mruslan97 as soon as you accept the CLA (#83923 (comment)) I am going to merge the PR.

@mruslan97 last, but not least big thanks for your contribution!

@adamsitnik adamsitnik added this to the 8.0.0 milestone May 18, 2023
@adamsitnik adamsitnik added the needs-author-action An issue or pull request that requires more info or actions from the author. label May 18, 2023
Copy link
Member

@danmoseley danmoseley left a comment

Choose a reason for hiding this comment

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

thanks, apologies for losing track of this one

danmoseley

This comment was marked as duplicate.

@mruslan97
Copy link
Contributor Author

@dotnet-policy-service agree

@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label May 31, 2023
@danmoseley danmoseley closed this May 31, 2023
@danmoseley danmoseley reopened this May 31, 2023
@danmoseley
Copy link
Member

rerunning tests

@adamsitnik
Copy link
Member

The failures are unrelated (#dotnet/arcade#11683, #76454), merging! :shipit:

@adamsitnik adamsitnik merged commit 7bcd509 into dotnet:main Jun 1, 2023
107 of 112 checks passed
@danmoseley
Copy link
Member

Thanks @mruslan97 for the contribution. We'd welcome another contribution in an area that interests you! Usually PRs go in faster than this one.

@mruslan97
Copy link
Contributor Author

Thank you guys! When I get some free time I'll try to do something even more useful in future

@dotnet dotnet locked as resolved and limited conversation to collaborators Jul 2, 2023
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zip64ExtraField should read StartDiskNumber as uint32
4 participants