-
Notifications
You must be signed in to change notification settings - Fork 27
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
Avoid segfault on bogus SVG data #412
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@a740g do we have any sense of where in nanosvg it blows up with a seg-fault?
I think ideally we'd address the issue in there, but only if it's simple enough. If it's a more fundamental problem with nanosvg then this type of approach makes sense, but we may want to consider looking for a replacement for nanosvg that correctly validates the input 🤷♂️
svgString[size] = '\0'; | ||
// Bail if we have binary data. We'll also copy the data while doing the check to avoid another pass | ||
for (size_t i = 0; i < size; i++) { | ||
auto c = svgString[i] = buffer[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that char
is typically signed so the +127 unicode values would trigger the c < 32
check (I think the auto
will be char
due to the type of svgString
). You should probably specify unsigned here if we want to allow them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct. Nice catch!
I am checking on this one now. It usually happens inside |
This PR avoids a segfault that happens when binary data pretending to be valid SVG text is passed to the SVG parser.
For example:
For memory loads we check the data byte by byte while copying the data for
nsvgParse()
.For file loads we check the file extension and check the data before passing it to
nsvgParse()
.