Skip to content

resvg_render() (C wrapper function) does not crash on incorrect input #926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

geometer
Copy link

Using the library in our C++ project via C wrappers, we found that the app crashes if SVG data are incorrect. E.g, contain extra chars after closing the root <svg> tag. The patch fixes that issue by catching a panic instead of throwing it into C++ code (where catching is impossible).

@LaurenzV
Copy link
Collaborator

I think the right fix for this is to fix the crash in the Rust version instead? What file are you having problems with, and what is the backtrace?

@RazrFalcon
Copy link
Collaborator

Catching panics is probably a good idea, but you are checking for tree.is_null() twice. That's not needed.
Also, the code/API is expected to fail/abort on invalid arguments, so that's should stay as before.
Basically, only std::panic::catch_unwind is needed here.
But if we're adding std::panic::catch_unwind - we have to add it to all function that can panic, not just render one.

And yes, we should also fix the cause of the crash, not just handling of it.

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.

3 participants