Skip to content

fix(diff): clamp Myers edit-distance operands to clear the allocation overflow alert#3775

Merged
esengine merged 1 commit into
main-v2from
fix/diff-alloc-overflow-2
Jun 10, 2026
Merged

fix(diff): clamp Myers edit-distance operands to clear the allocation overflow alert#3775
esengine merged 1 commit into
main-v2from
fix/diff-alloc-overflow-2

Conversation

@esengine

Copy link
Copy Markdown
Owner

Follow-up to #3773 to clear the remaining CodeQL go/allocation-size-overflow alert.

#3773 cleared the n + m addition alert, but CodeQL kept flagging the make([]int, 2*maxD+1) allocation: it doesn't propagate maxD's upper bound through the guarded sum, so it can't prove 2*maxD won't overflow.

This clamps each line count to maxDiffEdits before summing (cn, cm), so both the sum and the 2*maxD allocation have operands bounded by a constant — the canonical barrier CodeQL recognizes. maxD stays min(n+m, maxDiffEdits), identical behavior.

go build + go test ./internal/diff/ pass locally.

…tion

Follow-up to #3773: that cleared the n+m addition alert, but CodeQL still
flagged the 2*maxD allocation (go/allocation-size-overflow) because it
doesn't propagate maxD's bound through the guarded sum. Clamp each line
count to maxDiffEdits before summing, so the sum and the 2*maxD allocation
both have constant-bounded operands. maxD stays min(n+m, maxDiffEdits).
@esengine esengine requested a review from SivanCola as a code owner June 10, 2026 03:51
@github-actions github-actions Bot added the v2 Go rewrite (1.x) — main-v2 branch, active development label Jun 10, 2026
Comment thread internal/diff/diff.go
if cm > maxDiffEdits {
cm = maxDiffEdits
}
maxD := cn + cm
@esengine esengine merged commit f55aa47 into main-v2 Jun 10, 2026
13 of 14 checks passed
@esengine esengine deleted the fix/diff-alloc-overflow-2 branch June 10, 2026 03:55
SuMuxi66 pushed a commit to SuMuxi66/DeepSeek-Reasonix that referenced this pull request Jun 10, 2026
…tion (esengine#3775)

Follow-up to esengine#3773: that cleared the n+m addition alert, but CodeQL still
flagged the 2*maxD allocation (go/allocation-size-overflow) because it
doesn't propagate maxD's bound through the guarded sum. Clamp each line
count to maxDiffEdits before summing, so the sum and the 2*maxD allocation
both have constant-bounded operands. maxD stays min(n+m, maxDiffEdits).

Co-authored-by: reasonix <reasonix@deepseek.com>
dorokuma pushed a commit to dorokuma/DeepSeek-Reasonix that referenced this pull request Jun 10, 2026
…tion (esengine#3775)

Follow-up to esengine#3773: that cleared the n+m addition alert, but CodeQL still
flagged the 2*maxD allocation (go/allocation-size-overflow) because it
doesn't propagate maxD's bound through the guarded sum. Clamp each line
count to maxDiffEdits before summing, so the sum and the 2*maxD allocation
both have constant-bounded operands. maxD stays min(n+m, maxDiffEdits).

Co-authored-by: reasonix <reasonix@deepseek.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants