fix(codeql): go/incorrect-integer-conversion in pkg/model/provider/dmr/configure.go:158#3756
Merged
Sayt-0 merged 2 commits intoJul 20, 2026
Merged
Conversation
…r/configure.go:158 Add an explicit upper-bound check before narrowing the int64 context size to int32 in buildConfigureBackendConfig. If the value exceeds math.MaxInt32 (unrealistic for model context windows but possible in theory), it is clamped and a warning is logged rather than silently wrapping to a negative value. Also removes the //nolint:gosec directive that is no longer needed now that the conversion is provably safe after the guard. Fixes CodeQL rule go/incorrect-integer-conversion.
The first iteration added only an upper-bound check (v > math.MaxInt32), which left the negative range unsanitised — CodeQL go/incorrect-integer- conversion requires both bounds to be proven before a narrowing cast is considered safe. Replace the if/else chain with a switch: - v > math.MaxInt32: log a warning and clamp to MaxInt32 - 0 ≤ v ≤ MaxInt32: safe range, convert directly (int32(v)) - v < 0: log a warning and skip setting ContextSize (field stays nil) Treating negative context sizes as absent (nil) rather than clamping to zero avoids sending a potentially confusing context_size=0 to model-runner. Also adjusts the test added in the previous commit to match the new semantics.
ronan-thibaut-glitch
marked this pull request as ready for review
July 20, 2026 16:02
Sayt-0
enabled auto-merge
July 20, 2026 16:29
Sayt-0
approved these changes
Jul 20, 2026
This was referenced Jul 21, 2026
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.
An int64 value from
strconv.ParseInt(viaparseInt64Value) was narrowed directly to int32 inbuildConfigureBackendConfigwithout an upper-bound check, triggering CodeQL rulego/incorrect-integer-conversion. While context window sizes in excess of 2^31−1 are practically unreachable, a value that large would silently wrap to a negative int32, causing model invocation failures. The fix adds an explicit guard — if the int64 exceedsmath.MaxInt32, the value is clamped tomath.MaxInt32and a warning is logged; theint32conversion then operates on a provably in-range value. The now-redundant//nolint:gosecdirective is removed (confirmed by running golangci-lint with gosec enabled). A new test subcase covers the clamp path.