Skip to content

fix(semdiff): bound input size before the O(n*m) diff - #20

Merged
sujal-maheshwari2004 merged 1 commit into
mainfrom
fix/semdiff-bounded-memory
Nov 15, 2026
Merged

sujal-maheshwari2004 merged 1 commit into
mainfrom
fix/semdiff-bounded-memory

Conversation

@sujal-maheshwari2004

Copy link
Copy Markdown
Member

Security fix for GHSA-hhjj-px9x-pm54; the advisory is published with the release that contains it. Tested in the advisory's private fork and on current main (go vet, go test).

changes() allocated a full (n+1) x (m+1) LCS table and nothing limited the
input. DiffPrompt needs only a read token, so a request whose new_template is
a few MB of newlines allocated memory proportional to stored lines x request
lines (~330 MB for 400 KB of input) and could exhaust the server.

Analyze now returns ErrTooLarge, before allocating, when a version exceeds
MaxLines (1000) or MaxBytes (256 KiB); the table uses int32. The worst shape
found within the bounds (200 hunks) takes ~22 ms and ~7 MB.
@sujal-maheshwari2004
sujal-maheshwari2004 merged commit 51516cf into main Nov 15, 2026
2 checks passed
@sujal-maheshwari2004
sujal-maheshwari2004 deleted the fix/semdiff-bounded-memory branch November 15, 2026 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant