Skip to content

fix: catch panics in the Resvg constructor and in renderAsync() - #426

Open
schneefux wants to merge 1 commit into
thx:mainfrom
schneefux:catch-panic-in-constructor
Open

schneefux wants to merge 1 commit into
thx:mainfrom
schneefux:catch-panic-in-constructor

Conversation

@schneefux

Copy link
Copy Markdown

Follow-up to #396. render() has been guarded with catch_unwind since 2.7.0-alpha.1, but the constructor and renderAsync() are not. The constructor parses the SVG and shapes its text, so a panic there still aborts Node.js.

Reproduction

On a machine with a font installed that supports Balinese (e.g. Noto Sans Balinese on Linux, or standard macOS):

node -e "new (require('@resvg/resvg-js').Resvg)('<svg xmlns=\"http://www.w3.org/2000/svg\"><text>&#x1B44;</text></svg>')"
thread '<unnamed>' panicked at rustybuzz-0.7.0/src/complex/universal_machine.rs:370:58:
index out of bounds: the len is 1 but the index is 2
fatal runtime error: failed to initiate panic, error 5

Cause

The panic is a bug in rustybuzz 0.7.0, the text shaper of resvg 0.34. rustybuzz 0.9.0 fixed it (harfbuzz/rustybuzz#65), available since resvg 0.36. This PR does not fix the bug, but it turns the panic into an error that can be caught.

Note: Commit and PR were co-authored with Claude Fable 5.2

render() has been guarded with catch_unwind since 2.7.0-alpha.1, but
the constructor parses the SVG and converts text to paths, which runs
the text shaper. A panic there still aborted the Node.js process, for
example on a <text> holding a lone U+1B44 (Balinese virama), which
makes rustybuzz 0.7.0 read out of bounds.

- Wrap Resvg::new_inner in catch_unwind for the constructor and for
  AsyncRenderer::compute, and report it as Error::ParsePanic.
- Test both entry points with a test-only switch that makes new_inner
  panic, so the tests do not depend on a bug in resvg or rustybuzz.
- Run cargo test in the lint workflow.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 18, 2026

Copy link
Copy Markdown

@schneefux is attempting to deploy a commit to the yisibl's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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