Repository navigation
Conversation
Signed-off-by: gophersg <gopher@2980.com>
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.
Description
merkletree.Tree.ReadAllaccepts a publicsegmentSize intwith no validation.When
segmentSize == 0,io.ReadFull(r, make([]byte, 0))returns(0, nil), so theforloop never hits theio.EOFbreak and keeps pushing empty leaves forever.When
segmentSize < 0,make([]byte, segmentSize)panics withmakeslice: len out of range.Both
ReaderRootandBuildReaderProofcallReadAll, so a non-positive segmentsize (e.g. a computed/zero length from a caller) can hang the process or panic.
This is the same input-validation hardening class as #893 and #878.
This PR adds an early
segmentSize <= 0check at the top ofReadAlland returns aclear error, so all callers fail fast.
Type of change
How has this been tested?
go test ./accumulator/merkletree/ -run TestReadAll -v- TestReadAllRejectsNonPositiveSegmentSize: segmentSize 0 and -1 rejected by
ReadAll, ReaderRoot, and BuildReaderProof
- TestReadAllValidSegmentSize: positive segmentSize still builds the expected root
gofmt -lclean andgo vet ./accumulator/merkletree/cleanHow has this been benchmarked?
Checklist:
golangci-lintdoes not output errors locallyNote
Low Risk
Input validation only on an invalid edge case; valid positive segment sizes are unchanged per regression test.
Overview
Tree.ReadAllnow rejectssegmentSize <= 0up front withmerkletree: segment size must be positive, instead of infinite looping when size is 0 or panicking on negativemake([]byte, segmentSize).Because
ReaderRootandBuildReaderProofboth callReadAll, invalid segment sizes from callers now fail fast with that error.New tests cover rejection for 0 and -1 on
ReadAll,ReaderRoot, andBuildReaderProof, plus a regression check that a positive segment size still yields the same root as before.Reviewed by Cursor Bugbot for commit 49b6086. Bugbot is set up for automated code reviews on this repo. Configure here.