Skip to content

fix(svg): reject malformed 'd' that loops forever after a Z#186

Merged
DemchaAV merged 1 commit into
developfrom
fix/svg-path-parser-hang
Jun 14, 2026
Merged

fix(svg): reject malformed 'd' that loops forever after a Z#186
DemchaAV merged 1 commit into
developfrom
fix/svg-path-parser-hang

Conversation

@DemchaAV

Copy link
Copy Markdown
Owner

Why

Senior-review audit of the v1.8 SVG workstream surfaced a confirmed DoS in the @Beta SVG path reader: a Z/z close command consumes no operands, so a stray non-command token after it (e.g. "M0 0 Z5") made the scanner re-apply Z indefinitely, appending a close op to the ops list on every iteration until the heap was exhausted. Reachable from the public SvgPath.parse / SvgIcon surface on a single malformed (or hostile) path string.

What

  • SvgPathParser main loop gains a no-progress guard: if an iteration consumes neither a command letter nor an operand, it fails with the usual position-carrying IllegalArgumentException instead of spinning. Generic — covers any operand-less command followed by a stray token, not just Z.
  • SvgPathTest.strayTokenAfterCloseIsRejectedAndDoesNotHang pins it, wrapped in assertTimeoutPreemptively(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.

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.
@DemchaAV DemchaAV merged commit a1626c3 into develop Jun 14, 2026
11 checks passed
@DemchaAV DemchaAV deleted the fix/svg-path-parser-hang branch June 14, 2026 13:03
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