fix: Import math and validate request body size - #7535
Open
odaysec wants to merge 2 commits into
Open
Conversation
Add math import and check for bulk request body size. fix protect all allocation-size arithmetic by checking for overflow before computing/using capacities. For this specific issue, make `Buf.grow` compute a target capacity without overflowing, and panic with a clear message if growth cannot be represented as `int`. Best targeted fix (no functional change beyond safety): - Edit `internal/pkg/danger/buf.go`, function `grow`. - Replace `2*cap(b.buf)+n` with guarded arithmetic: - Validate `n >= 0` (defensive, even though `Grow` checks). - Compute required capacity `need := len(b.buf) + n` with overflow check. - Compute doubled capacity from current cap with overflow check/saturation. - Choose `newCap = max(need, doubledCap)`. - Allocate with `make([]byte, len(b.buf), newCap)`. - Add `math` import for `math.MaxInt`.
Contributor
|
This pull request does not have a backport label. Could you fix it @ekuboo100? 🙏
|
odaysec
commented
Aug 1, 2026
kruskall
reviewed
Aug 2, 2026
|
|
||
| // Serialize request | ||
| const kSlop = 64 | ||
| if len(body) > math.MaxInt-kSlop { |
Member
There was a problem hiding this comment.
Could you share what system you are running to have a byte slice of len(math.MaxInt) in memory ?
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.
Add math import and check for bulk request body size. fix protect all allocation-size arithmetic by checking for overflow before computing/using capacities. For this specific issue, make
Buf.growcompute a target capacity without overflowing, and panic with a clear message if growth cannot be represented asint.Best targeted fix (no functional change beyond safety):
internal/pkg/danger/buf.go, functiongrow.2*cap(b.buf)+nwith guarded arithmetic:n >= 0(defensive, even thoughGrowchecks).need := len(b.buf) + nwith overflow check.newCap = max(need, doubledCap).make([]byte, len(b.buf), newCap).mathimport formath.MaxInt.Design Checklist
Checklist
./changelog/fragmentsusing the changelog toolRelated issues