Skip to content

UPSTREAM PR #26914: C#: fix IndexOutOfRangeException in ReadRawByte on truncated messages#144

Open
loci-dev wants to merge 1 commit intomainfrom
loci/pr-26914-fix-csharp-readrawbyte-ioob-truncated-message
Open

UPSTREAM PR #26914: C#: fix IndexOutOfRangeException in ReadRawByte on truncated messages#144
loci-dev wants to merge 1 commit intomainfrom
loci/pr-26914-fix-csharp-readrawbyte-ioob-truncated-message

Conversation

@loci-dev
Copy link
Copy Markdown

Note

Source pull request: protocolbuffers/protobuf#26914

Summary
A near-int.MaxValue length varint overflows PushLimit, corrupting bufferSize to a negative value. ReadRawByte's == guard then never triggers RefillBuffer, causing an out-of-bounds read instead of InvalidProtocolBufferException.TruncatedMessage().

Fix
change == to >= in ReadRawByte. Regression tests added for all four affected slow-path variants.

Tests
Added TruncatedMessageWithLargeInnerLengthThrowsInvalidProtocolBufferException with 4 test cases.

Fixes #26856

@loci-dev loci-dev force-pushed the main branch 30 times, most recently from cac2d55 to 558f1f4 Compare April 22, 2026 14:09
@loci-dev loci-dev force-pushed the main branch 15 times, most recently from 847b67c to 75c1917 Compare April 24, 2026 14:07
Compute the absolute limit in long arithmetic so overflow no longer
leaves state.currentLimit negative.

Fixes #26856
@loci-dev loci-dev force-pushed the loci/pr-26914-fix-csharp-readrawbyte-ioob-truncated-message branch from 8fcb410 to 355e425 Compare April 24, 2026 15:52
@loci-review
Copy link
Copy Markdown

loci-review Bot commented Apr 24, 2026

No meaningful performance changes were detected across 10164 analyzed functions in the following binaries: build.protoc-stable.

💬 Questions? Tag @loci-dev

@loci-dev loci-dev force-pushed the main branch 8 times, most recently from f292971 to 1fdfb93 Compare April 29, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant