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

[tx] fix segfaults due to old function call #1649

Merged
merged 4 commits into from
May 5, 2023

Conversation

kaydeearts
Copy link
Collaborator

@kaydeearts kaydeearts commented May 5, 2023

Description

Frank reported a bug where makeotf crashed with segfault due to an unexpected point type in a glif file. There was error handling already set up for this, but called a function getBufferContextPtr that was meant for the pre-libxml2 way of parsing tokens. I removed all calls of this function where the caller is using the libxml2 way of parsing and added some test cases.

Side note: There are some unused token parsing functions leftover in uforead that I would like to clean up in a separate PR. I partly kept them there in case they illustrated functions that we needed to convert to libxml2 — doesn't look like it from a quick glance, but I'll investigate this further.

Checklist:

  • I have followed the Contribution Guidelines
  • I have added test code and data to prove that my code functions correctly
  • I have verified that new and existing tests pass locally with my changes
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

@kaydeearts kaydeearts requested a review from skef May 5, 2023 22:12
@kaydeearts
Copy link
Collaborator Author

I think we've discussed this before already, but we definitely need to make these fatals vs fprintf vs returning error code ways of error handling more consistent. Let me know if you have thoughts for the ones I did in this PR, and we can also discuss the overall usage of these various ways in our next team meeting!

Comment on lines -1190 to -1192
if (fileName == NULL) {
fatal(h, ufoErrParse, "Encountered glyph reference in contents.plist with an empty file path. Text: '%s'.", getBufferContextPtr(h));
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I deleted this after trying to reach this with various test cases — I believe it is unreachable. addNewGLIFRec is called from two functions: parseCIDMap and addGLIFRec. When called from parseCIDMap, this should not be reachable since we do not proceed to these lines of code if parsing the CIDMap. When called from addGLIFRec, since it already handles this before calling addNewGLIFRec, it is already handled by the time these lines are reached. This is why I thought this was repetitive and unnecessary.

Comment on lines -1494 to -1500
if (h->stm.src == NULL) {
fprintf(stderr, "Failed to open glif file in parseGLIF: %s.\n", glifRec->glifFilePath);
return ufoErrSrcStream;
}
if (h->cb.stm.seek(&h->cb.stm, h->stm.src, 0)) {
fprintf(stderr, "Failed to open glif file in parseGLIF: %s.\n", glifRec->glifFilePath);
return ufoErrSrcStream;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I condensed these fatals into one if statement, but truthfully I'm not sure what the difference between these two are. I understand the first one (my test case is a missing glif file), but not sure if/how I can reach the second line.

Comment on lines -2527 to -2531
if (gi == NULL) {
message(h, "Missing component base attribute. Glyph: %s, Context: %s.\n", glifRec->glifFilePath, getBufferContextPtr(h));
result = ufoErrNoGlyph;
return result;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was unsure about whether or not I should remove this for repetitiveness. I experimented with ways to getting to these lines, but they all were caught by line 2611 (in the updated file). Looking further into it, this function is called within parseGLIF, while line 2611 is called while within preParseGLIF. Since preParseGLIF is before parseGLIF, this should technically be dealt with already (as my test cases showed). However, I'm still unsure. I can leave it in while removing the getBufferContextPtr, but I don't have an idea for how to test it.

Comment on lines -3070 to -3071
fprintf(stderr, "Failed to open glif file in parseGLIFOutline. Glyph: %s. Context: %s\n.", glifRec->glyphName, getBufferContextPtr(h));
fatal(h, ufoErrSrcStream, 0);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reworded this so we're not referring to a function call in an error message as well as removed getBufferContextPtr

@skef
Copy link
Collaborator

skef commented May 5, 2023

I think we've discussed this before already, but we definitely need to make these fatals vs fprintf vs returning error code ways of error handling more consistent. Let me know if you have thoughts for the ones I did in this PR, and we can also discuss the overall usage of these various ways in our next team meeting!

Logging is already quite different in my future-work branches. The less we change things in develop the less work I have to do porting PRs over.

Copy link
Collaborator

@skef skef left a comment

Choose a reason for hiding this comment

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

LGTM

@kaydeearts
Copy link
Collaborator Author

LGTM

That was SO FAST that I couldn't even finish writing a response to Frank's message 😆 thank you!

@kaydeearts kaydeearts merged commit a58fcc5 into develop May 5, 2023
@kaydeearts kaydeearts deleted the kd-fix-segfault-minus branch May 5, 2023 22:28
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.

2 participants