FIX: Added ft2font null checks added#31557
Conversation
|
Do I need to write a test for this? The changes feel pretty trivial. |
Please do, it's worth checking that this code can be triggered. |
I just took a look at a test for this. The |
|
@story645 Any thoughts? If the testing requirement is stringent and you can think of any alternatives/somebody else wants to take it over, I can also close it out. |
does that mean the error message "unknown error" never gets propagated up? And I think here the testing requirement isn't that stringent - looks like the coverage decreases are unrelated. |
After digging a little bit, the only font format where FreeType would reutnr a null family_name is BDF (bitmap fonts without a FAMILY_NAME property), but matplotlib's The null check is really more just preventative but seems like it may honestly just never be triggered. From a correctness standpoint, it won't hurt. |
QuLogic
left a comment
There was a problem hiding this comment.
I don't really see any way that FT_ERROR_END_LIST would be triggered, but might as well be safe.
|
I am a bit unconvinced by the need to remove NULL in at least the error list case. The docs for the correlating Freetype function specifically say it can return NULL: https://freetype.org/freetype2/docs/reference/ft2-error_enumerations.html The example code for how to interact with these also includes a NULL (though interestingly only in one of the two examples, and not in the version that is most similar to what we have with a Given that NULL is an expected, documented return value here, I do not see the need to preemptively remove a NULL. |
Sorry if I'm not following but given the fact that we expect a NULL shouldn't we guard against that in order to avoid de referencing a NULL pointer? |
|
I am referring to the change to I am not referring to the check when dereferencing. |
Ah ok, I see what you're getting at. Leaning towards your argument; can revert the change if others agree but honestly this feels like a relatively uneventful, trivial change. |
|
This is a weird one, because we aren't actually using
However, since we aren't using |
|
FT_Error_String is relatively new (it's there since FT 2.10.0, which we still don't actually require). I guess we could bump the required FT version, though. |
Yea, probably we should tighten up what version is required there, but that's a separate question. |
…557-on-v3.11.x Backport PR #31557 on branch v3.11.x (FIX: Added ft2font null checks added)
PR summary
Fix two potential null pointer crashes in
src/ft2font.handsrc/ft2font_wrapper.cpp.1.
ft_error_stringreturning NULL (ft2font.h:44)Fixed by changing the
defaultcase to return"unknown error"instead ofNULL, so the function always returns a valid string.2. NULL
family_namestreamed inft_glyph_warn(ft2font_wrapper.cpp:408)Fixed by guarding each stream insertion with
(*it ? *it : "unknown").AI Disclosure
I used Claude Code to help understand the codebase. The fixes were applied by me.
PR checklist