From e876e81beb9e5200be990803115996ebea540319 Mon Sep 17 00:00:00 2001 From: "Jorj X. McKie" Date: Mon, 14 Nov 2022 11:01:27 -0400 Subject: [PATCH] Fix #2045 - immunize against non-UTF8 encoded fontnames Python C function `Py_BuildValue("s", fontname)` will fail if fontname is not UTF8-encoded. Use PyUnicodeRawEscape function for fontnames instead - like everywhere else in PyMuPDF. --- fitz/helper-devices.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fitz/helper-devices.i b/fitz/helper-devices.i index 18e0519e5..e4253bfe9 100644 --- a/fitz/helper-devices.i +++ b/fitz/helper-devices.i @@ -493,7 +493,7 @@ jm_trace_text_span(fz_context *ctx, PyObject *out, fz_text_span *span, int type, // make the span dictionary PyObject *span_dict = PyDict_New(); DICT_SETITEMSTR_DROP(span_dict, "dir", JM_py_from_point(dir)); - DICT_SETITEM_DROP(span_dict, dictkey_font, Py_BuildValue("s",fontname)); + DICT_SETITEM_DROP(span_dict, dictkey_font, JM_EscapeStrFromStr(fontname)); DICT_SETITEM_DROP(span_dict, dictkey_wmode, PyLong_FromLong((long) span->wmode)); DICT_SETITEM_DROP(span_dict, dictkey_flags, PyLong_FromLong((long) fflags)); DICT_SETITEMSTR_DROP(span_dict, "bidi_lvl", PyLong_FromLong((long) span->bidi_level));