-
Notifications
You must be signed in to change notification settings - Fork 510
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
Segmentation fault for Font(fontbuffer=object())
#838
Comments
Looks like that normally there's a check, but in this case it's missing. The straight forward fix would be --- a/fitz/helper-stext.i
+++ b/fitz/helper-stext.i
@@ -830,6 +830,7 @@ fz_font *JM_get_font(fz_context *ctx,
// fontbuffer
have_buffer:;
res = JM_BufferFromBytes(ctx, fontbuffer);
+ if (!res) THROWMSG(gctx, "bad type: 'fontbuffer'");
font = fz_new_font_from_buffer(ctx, NULL, res, index, 0);
goto fertig; but in this case it raises a warning (also is there a memory leak?) Searching a bit in the source code, there are some other instances that the result is not checked against null value. (twice in |
Thanks for spotting this. |
I usually use a macro |
I also encountered a similar error. When encountering this "Segmentation fault: 11" exception, "try: except:" cannot recognize this exception, and the program will exit abnormally. Is there any other way to identify this kind of exception in python? |
No - and that exactly is the problem - the Python interpreter itself is brought down. |
There's Also, since this error is not fixed (in the newest version on GitHub/pypi), it might be the same (or related) error.
|
Fixed by v1.18.7, currently being uploaded. |
Please provide all mandatory information!
Describe the bug (mandatory)
fitz.Font(fontbuffer=object())
causes a segmentation fault.To Reproduce (mandatory)
See above.
Expected behavior (optional)
It should raise a
TypeError
or something.Your configuration (mandatory)
Python 3.9.1, wheel.
Additional context (optional)
This is not how the library is supposed to be used, but mistakes can happen (for example pass a
fontTools.TTFont
object in), and segmentation faults are annoying in Python (normally it would print a traceback and let the user catch it)To generalize, perhaps there should be some way to make the functions that take
AnyType
arguments safe from user errors?The text was updated successfully, but these errors were encountered: