| 1 | This patch fixes a crash in the libxml2 bindings for Python 3.x
|
| 2 | that 'itstool' stumbles upon when processing UTF-8 data:
|
| 3 |
|
| 4 | https://issues.guix.gnu.org/issue/37468
|
| 5 |
|
| 6 | Patch by Jan Matejek
|
| 7 | from <https://bugzilla.opensuse.org/show_bug.cgi?id=1065270>.
|
| 8 |
|
| 9 | |
| 10 | |
| 11 | @@ -1499,6 +1499,7 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg,
|
| 12 | PyObject *message;
|
| 13 | PyObject *result;
|
| 14 | char str[1000];
|
| 15 | + unsigned char *ptr = (unsigned char *)str;
|
| 16 |
|
| 17 | if (libxml_xmlPythonErrorFuncHandler == NULL) {
|
| 18 | va_start(ap, msg);
|
| 19 | @@ -1510,12 +1511,20 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg,
|
| 20 | str[999] = 0;
|
| 21 | va_end(ap);
|
| 22 |
|
| 23 | +#if PY_MAJOR_VERSION >= 3
|
| 24 | + /* Ensure the error string doesn't start at UTF8 continuation. */
|
| 25 | + while (*ptr && (*ptr & 0xc0) == 0x80)
|
| 26 | + ptr++;
|
| 27 | +#endif
|
| 28 | +
|
| 29 | list = PyTuple_New(2);
|
| 30 | PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt);
|
| 31 | Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
|
| 32 | - message = libxml_charPtrConstWrap(str);
|
| 33 | + message = libxml_charPtrConstWrap(ptr);
|
| 34 | PyTuple_SetItem(list, 1, message);
|
| 35 | result = PyObject_CallObject(libxml_xmlPythonErrorFuncHandler, list);
|
| 36 | + /* Forget any errors caused in the error handler. */
|
| 37 | + PyErr_Clear();
|
| 38 | Py_XDECREF(list);
|
| 39 | Py_XDECREF(result);
|
| 40 | }
|