fix: adding length validation on deserialization #19415
Open
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.
Summary
Add semantic validation to P2P message deserialization to reject protocol-violating array/string lengths. This prevents DoS attacks via maliciously crafted messages that specify enormous sizes, which could cause memory exhaustion before the buffer range check catches the issue.
Changes
Foundation Layer
maxSizeparameter toreadVector(),readBuffer(), andreadString()methods. This is a non-breaking change - all 161+ existing calls continue to work unchanged.Constants Organization
stdlib/deserialization: New module with shared constants:
MAX_TXS_PER_BLOCK= 2 ** 16 (65536)MAX_COMMITTEE_SIZE = 2,048(theoretical max from bitmap design: 256 bytes × 8 bits)MAX_BLOCKS_PER_CHECKPOINT = 72MAX_TX_EFFECTS_PER_BODY = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOBMAX_BLOCK_HASH_STRING_LENGTH = 128p2p/reqresp/constants: P2P-specific constants:
MAX_VERSION_STRING_LENGTH = 64MAX_BLOCK_HASH_STRING_LENGTH = 128MAX_TXS_PER_BLOCKfrom stdlibBounds Checking Added To
BlockProposal.fromBufferCheckpoint.fromBufferPublishedCheckpoint.fromBufferBody.fromBufferCheckpointedL2Block.fromBufferPublishedL2Block.fromBufferdeserializeValidateBlockResultStatusMessage.fromBufferBitVector.fromBufferTests
BufferReadermaxSize bounds checkingBitVectorbounds validationFixes A-273