Skip to content

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

Closed
FUTURE-SL wants to merge 1 commit intodotnet:mainfrom
FUTURE-SL:alloc-prevent
Closed

Add minimum remaining-data checks for fixed-size binary reads#125698
FUTURE-SL wants to merge 1 commit intodotnet:mainfrom
FUTURE-SL:alloc-prevent

Conversation

@FUTURE-SL
Copy link

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
Contributor

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

@FUTURE-SL
Copy link
Author

@dotnet-policy-service agree

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

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