fix: security bugs: ReadHashSet allocation attack, Unbatcher overflow#4115
Merged
Conversation
…ctionary.Remove contract
…ervice ReadList and ReadArray guard against allocation attacks with AllocationLimit, but ReadHashSet was missing this check entirely. A malicious peer could send a huge length value and force the receiver to allocate unbounded memory.
DecompressVarUInt returns ulong. Casting directly to int silently wraps values > int.MaxValue to negative, which bypasses the reader.Remaining < size validation. Now validates the raw ulong against int.MaxValue before casting.
…ving Previously only checked the key, ignoring the value entirely. This violated the IDictionary<TKey,TValue> contract which requires both key AND value to match for removal.
Copilot
AI
changed the title
Fix 3 bugs: ReadHashSet allocation attack, Unbatcher integer overflow, SyncDictionary.Remove contract
Fix 3 security/correctness bugs: ReadHashSet allocation attack, Unbatcher overflow, SyncDictionary contract
Jun 27, 2026
Copilot created this pull request from a session on behalf of
miwarnec
June 27, 2026 08:53
View session
Collaborator
|
@copilot drop the syncdictionary change |
Contributor
Author
Reverted in |
Copilot
AI
changed the title
Fix 3 security/correctness bugs: ReadHashSet allocation attack, Unbatcher overflow, SyncDictionary contract
Fix 2 security bugs: ReadHashSet allocation attack, Unbatcher overflow
Jun 27, 2026
Collaborator
|
@copilot add test coverage if its low overhead to our existin gtests |
…rflow - TestReadHashSet_LengthIsTooBig: mirrors existing ReadList/ReadArray tests - GetNextMessage_SizePrefixOverflow_Throws: verifies size > int.MaxValue throws
Contributor
Author
Added in
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4115 +/- ##
==========================================
+ Coverage 42.19% 42.22% +0.03%
==========================================
Files 156 156
Lines 15092 15100 +8
==========================================
+ Hits 6368 6376 +8
Misses 8724 8724
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two independent security bugs, one per commit.
ReadHashSet missing allocation limit (
NetworkReaderExtensions.cs)ReadListandReadArrayboth guard against allocation attacks viaNetworkReader.AllocationLimit.ReadHashSetwas missing this check — a malicious peer can send an arbitrarily large length and force unbounded allocation (DoS).Unbatcher integer overflow on size prefix (
Unbatcher.cs)DecompressVarUIntreturnsulong. The direct cast tointwraps values >int.MaxValueto negative, which silently passesreader.Remaining < size(negative is always less). A malformed batch bypasses size validation entirely.