Skip to content

Validate Serialized String Lengths Before Allocation - #2474

Merged
Brian Robbins (brianrob) merged 1 commit into
microsoft:mainfrom
brianrob:brianrob/validate-serialized-string-lengths
Oct 6, 2026
Merged

Brian Robbins (brianrob) merged 1 commit into
microsoft:mainfrom
brianrob:brianrob/validate-serialized-string-lengths

Conversation

@brianrob

@brianrob Brian Robbins (brianrob) commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Malformed serialized input can cause ReadString() to allocate excessive memory from an untrusted character count before detecting truncated content.

Validate string counts before allocating or resetting the builder: accept only -1 as null, reject other negative counts, and check against remaining bytes when the stream length is known. Known-length readers preallocate the validated count; non-seekable readers use a bounded initial capacity and grow as content is decoded. The existing wire format is unchanged.

Add regression coverage for oversized and invalid counts, non-seekable allocation behavior, malformed type names, truncated characters, and compatibility with valid strings.

@brianrob
Brian Robbins (brianrob) enabled auto-merge (squash) October 6, 2026 15:34
@brianrob
Brian Robbins (brianrob) merged commit e35d129 into microsoft:main Oct 6, 2026
5 checks passed
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.

2 participants