Skip to content
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

Fix several segfaults #5306

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ttxine
Copy link

@ttxine ttxine commented Oct 27, 2023

Fixed segfaults in:

  • SplineFontFromPSFont()
    If fd->wascff was true, then sf was set to fd->sf, which is always NULL. And sf->multilayer check caused a segfault.

  • readcffglyphs()
    readcfffontnames() may return NULL.

  • readcfffontnames()
    (offsets[i+1]-offsets[i]) could be equal to UINT32_MAX, which led to malloc(0) call, but the loop exit condition remained j < UINT32_MAX.

Type of change

  • Bug fix

@ttxine ttxine marked this pull request as ready for review October 27, 2023 12:34
@@ -2735,6 +2735,14 @@ return( NULL );
++i;
}
--i;
} else if ( (offsets[i+1]-offsets[i])==UINT32_MAX ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a weirdly specific problem. Normally one would worry about a more general class of strings that are too large. Here you're finding the offset difference is exactly UINT32_MAX. That strongly implies (to me, anyway) that some other code is causing the difference to be that value, and adding this fix would just disguise that problem.

Before we do this we should at least try to figure out why we're seeing such a specific symptom. Do you have an example file?

@@ -3014,7 +3014,7 @@ SplineFont *SplineFontFromPSFont(FontDict *fd) {
SplineFontMetaData(sf,fd);
if ( fd->wascff ) {
SplineFontFree(sf);
sf = fd->sf;
return ( NULL );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not doing the unindented returns anymore. Some of those are left over from the old days.

Still, this may not be quite right. I assume the problem is that fd->sf can be NULL, and then (for example) the sf->multilayer check below will fail? That's true, but in that case shouldn't we first check if fd->sf is NULL, return if it is, and otherwise do what's there now?

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