Repository navigation
fix(base): resolve the CodeQL integer-conversion alert on download content length - #379
Merged
Merged
Conversation
…ntent length Rewrite the download ContentLength saturation with an explicit math.MaxInt upper-bound guard that CodeQL recognizes as a sanitizer, replacing the int64(^uint(0)>>1) expression it could not follow. Behavior is unchanged: the exported FileReader.ContentLength still saturates at the platform maximum int without limiting the response body, and the 32-bit large-file tests pass unchanged. Clears code-scanning alert #9. Closes #378
ffumero2003
requested review from
goanpeca and
sophiecarreras
as code owners
November 10, 2026 21:55
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.
Problem
CodeQL reports a high
go/incorrect-integer-conversionalert (#9) onmainatbase/base.goinnewFileReaderWithMaxLength:The cast is provably safe —
min(..., int64(^uint(0)>>1))clamps to the platform maximumint— but CodeQL does not recognizeint64(^uint(0)>>1)as a bound, so it flags it. The open alert holds the release (make release-check, per RELEASE.md).Changes
Rewrite the saturation with an explicit
math.MaxIntupper-bound guard — the pattern CodeQL recognizes as a sanitizer, and clearer to read:Behavior is identical:
int64(^uint(0)>>1)ismath.MaxInt, so the old triple-minand the new guard compute the same value.base.FileReader.ContentLengthstill saturates at the platform maximumintwithout limiting the response body;maxIntremains the test seam for the 32-bit path.Verification
go build ./...,go vet ./base,gofmt -l base/base.go: clean.go test -race ./base ./b2/...: PASS (base, b2, b2/sync), including the fix(base): preserve large-file responses on 32-bit targets #370 32-bit content-length tests.mainafter merge; alert Fix test broken by 83b9008 #9 is expected to clear. If it does not, the conversion will be adjusted further.Behavior-preserving internal change, no user-facing behavior change (
skip-changelog).Closes #378