Skip to content

Conversation

edwardneal
Copy link
Contributor

Fixes #114026. Swaps references to Stream.Read out with Stream.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 than Stream.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

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 4, 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
Contributor

@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 this change, @edwardneal. I left some comments/questions for you to consider.

Copy link
Contributor

@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.

LGTM modulo the debug question.

@carlossanlop
Copy link
Contributor

/ba-g runtime-libraries-coreclr outerloop

@carlossanlop carlossanlop merged commit 1b090a9 into dotnet:main Apr 15, 2025
81 of 87 checks passed
@edwardneal edwardneal deleted the ziparchive-stream-read branch April 15, 2025 03:32
@github-actions github-actions bot locked and limited conversation to collaborators May 15, 2025
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.

Replace ZipArchive calls of stream.Read with stream.ReadExactly or stream.ReadAtLeast

2 participants