Use Stream.ReadAtLeast when loading ZipArchives#114256
Merged
carlossanlop merged 7 commits intodotnet:mainfrom Apr 15, 2025
Merged
Use Stream.ReadAtLeast when loading ZipArchives#114256carlossanlop merged 7 commits intodotnet:mainfrom
Stream.ReadAtLeast when loading ZipArchives#114256carlossanlop merged 7 commits intodotnet:mainfrom
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-io-compression |
This was referenced Apr 4, 2025
This was referenced Apr 8, 2025
carlossanlop
reviewed
Apr 9, 2025
Contributor
carlossanlop
left a comment
There was a problem hiding this comment.
Thanks for this change, @edwardneal. I left some comments/questions for you to consider.
src/libraries/System.IO.Compression/tests/ZipArchive/zip_ReadTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/tests/System.IO.Compression.Tests.csproj
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.cs
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.cs
Show resolved
Hide resolved
src/libraries/System.IO.Compression/tests/Utilities/ClampedReadStream.cs
Show resolved
Hide resolved
src/libraries/System.IO.Compression/tests/ZipArchive/zip_ReadTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.cs
Outdated
Show resolved
Hide resolved
carlossanlop
approved these changes
Apr 14, 2025
Contributor
carlossanlop
left a comment
There was a problem hiding this comment.
LGTM modulo the debug question.
Contributor
|
/ba-g runtime-libraries-coreclr outerloop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #114026. Swaps references to
Stream.Readout withStream.ReadAtLeast, adds a test to prove the correct behaviour.In every case except for ZipArchive, we use a pattern of calling
Stream.ReadAtLeast(Span, Span.Length, throwOnEndOfStream: false)rather thanStream.ReadExactly(Span). The surrounding code checks the number of bytes read and returns false, and I didn't want to change that pattern.The ZipArchive case takes place when reading the central directory, and it makes sure to always read enough bytes for the constant component of a ZipCentralDirectoryFileHeader.
/cc @carlossanlop