Skip to content

fix(base): resolve the CodeQL integer-conversion alert on download content length - #379

Merged
ffumero2003 merged 1 commit into
mainfrom
fix-base-issue-378-codeql-intconv
Nov 10, 2026
Merged

ffumero2003 merged 1 commit into
mainfrom
fix-base-issue-378-codeql-intconv

Conversation

@ffumero2003

Copy link
Copy Markdown
Contributor

Problem

CodeQL reports a high go/incorrect-integer-conversion alert (#9) on main at base/base.go in newFileReaderWithMaxLength:

ContentLength: int(min(contentLength, maxInt, int64(^uint(0)>>1))),

The cast is provably safe — min(..., int64(^uint(0)>>1)) clamps to the platform maximum int — but CodeQL does not recognize int64(^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.MaxInt upper-bound guard — the pattern CodeQL recognizes as a sanitizer, and clearer to read:

length := min(contentLength, maxInt)
if length > math.MaxInt {
    length = math.MaxInt
}
// ...
ContentLength: int(length),

Behavior is identical: int64(^uint(0)>>1) is math.MaxInt, so the old triple-min and the new guard compute the same value. base.FileReader.ContentLength still saturates at the platform maximum int without limiting the response body; maxInt remains the test seam for the 32-bit path.

Verification

Behavior-preserving internal change, no user-facing behavior change (skip-changelog).

Closes #378

…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 ffumero2003 added ci Continuous integration and workflow changes skip-changelog No changelog entry needed; skips the changelog check labels Nov 10, 2026
@ffumero2003 ffumero2003 self-assigned this Nov 10, 2026
@ffumero2003
ffumero2003 merged commit 84242db into main Nov 10, 2026
24 of 25 checks passed
@ffumero2003
ffumero2003 deleted the fix-base-issue-378-codeql-intconv branch November 10, 2026 21:57
Comment thread base/base.go Dismissed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continuous integration and workflow changes skip-changelog No changelog entry needed; skips the changelog check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(base): resolve the CodeQL integer-conversion alert on download content length

2 participants