fix(svg): reject malformed 'd' that loops forever after a Z#186
Merged
Conversation
A Z/z close command consumes no operands, so a stray non-command token after it (e.g. "M0 0 Z5") made the path scanner re-apply Z indefinitely, appending a close op every pass until the heap was exhausted — a DoS reachable from the @beta SvgPath.parse / SvgIcon public surface on a single malformed path string. Add a no-progress guard to the scan loop: if an iteration consumes neither a command letter nor an operand, fail with the usual position-carrying IllegalArgumentException instead of spinning. SvgPathTest gains a regression case wrapped in assertTimeoutPreemptively so the hang can never silently return.
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.
Why
Senior-review audit of the v1.8 SVG workstream surfaced a confirmed DoS in the
@BetaSVG path reader: aZ/zclose command consumes no operands, so a stray non-command token after it (e.g."M0 0 Z5") made the scanner re-applyZindefinitely, appending a close op to the ops list on every iteration until the heap was exhausted. Reachable from the publicSvgPath.parse/SvgIconsurface on a single malformed (or hostile) path string.What
SvgPathParsermain loop gains a no-progress guard: if an iteration consumes neither a command letter nor an operand, it fails with the usual position-carryingIllegalArgumentExceptioninstead of spinning. Generic — covers any operand-less command followed by a stray token, not justZ.SvgPathTest.strayTokenAfterCloseIsRejectedAndDoesNotHangpins it, wrapped inassertTimeoutPreemptively(2s)so the hang can never silently return.Tests
./mvnw test -Dtest=SvgPathTest -pl .→ 15/15, BUILD SUCCESS. Valid paths ("M0 0 Z","M0 0 Z Z", implicit repeats) unaffected.Lane: canonical /
document.svg(@beta). No public-surface change.