Skip to content

Add minimum remaining-data checks for fixed-size binary reads - #125698

Closed
I-WAS-FUTURE wants to merge 1 commit into
dotnet:mainfrom
I-WAS-FUTURE:alloc-prevent
Closed

I-WAS-FUTURE wants to merge 1 commit into
dotnet:mainfrom
I-WAS-FUTURE:alloc-prevent

Conversation

@I-WAS-FUTURE

Copy link
Copy Markdown

This change adds pre-read validation for operations where the required byte count is known in advance.

What changed:

  • added EnsureCanRead(int byteCount)
  • used it in InternalRead(Span<byte>)
  • used it in ReadExactly(Span<byte>)
  • used it in ReadString() after reading the encoded byte length

Why:

  • fail earlier on seekable streams when there is not enough remaining data
  • avoid starting partial reads for fixed-size values and length-prefixed strings
  • improve behavior for truncated or malformed inputs without introducing hard size limits

Added EnsureCanRead method to validate read operations and prevent reading beyond stream limits.
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Mar 17, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@I-WAS-FUTURE

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.IO 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.

1 participant