Fixing a stack-overflow DoS in OSV-Scanner's SPDX license parser #1
Amey-Thakur
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
OSV-Scanner · SPDX Parser · Stack-Overflow Fix
This fork exists for one contribution to Google's OSV-Scanner: finding and fixing a denial-of-service in its SPDX license parser. Merged into
mainon 2 September 2026, and the issue closed as completed the same minute.The full write-up is here: A Stack-Overflow Denial of Service in Google's OSV-Scanner, covering the mechanism, the merged code, the regression test, and what contributing upstream to Google involved.
The bug
spdx.Satisfiesparses SPDX license expressions with an unbounded recursive descent. License strings are untrusted input, taken from the metadata of whatever packages are being scanned. A license string of deeply nested brackets recurses until the goroutine stack overflows, and a Go stack overflow is a fatal error thatrecovercannot catch, so the entire scan process aborts. Roughly a 3 MB string of(characters is enough.CWE-674, Uncontrolled Recursion.
The fix
A nesting-depth counter threaded through the recursive descent. Past a generous ceiling of 1,000 levels, the parser returns an ordinary parse error instead of recursing further. Real SPDX expressions nest only a few levels, so nothing legitimate is rejected; an over-nested expression now fails like any other invalid input rather than killing the process.
The trail
main1c93dc4fix/spdx-recursion-depth-limitVerification
go test ./internal/spdx/passes;gofmtandgo vetare clean.The whole thing, in one animation
Four beats, and it is built to be understood without reading any Go. The
nesting is drawn as rectangles closing inward, which is what deepening
recursion looks like, and the number on screen is the depth the parser was
actually tracking as it descended.
The three renderings
All 1080 x 1080, generated from one frame list so they cannot disagree with
each other.
spdx-recursion-fix.mp4spdx-recursion-fix.gifspdx-recursion-fix-loop.gifThe short loop, for a feed that scrolls faster:
They live on the
mediabranch of this fork, which is an orphan branch sharing no history with
mainorwith the branch that was merged. Neither of those should carry media that was
never part of the change.
Where it stands
The fix is on
main. It is not in a tagged release yet: the newest release at the time of writing is v2.5.1 from 17 August 2026, which predates the merge. Anyone who needs the fix today builds frommain; everyone else gets it in the next release.More open-source work is indexed at github.com/Amey-Thakur
All reactions