Sat Jun 12 17:02:52 2021 UTC ()
py-libxml2: work around a problem in error handling

Restore part of a patch lost in the last libxml2 update which is still
relevant. Reapplying it fixes segfaults caused by itstool, e.g., when
building editors/pluma, which is PR pkg/56229 from Andrius V.

Quoting from wiz@'s original commit from Jan 9, 2019, which covers
everything else:

"In some cases, invalid UTF-8 strings were returned which caused
Python interpreter crashes. See

itstool/itstool#22

Use a variant of the patch that was used in Fedora.

Bump PKGREVISION."

Fedora is still carrying this patch as-is.

(Also, evidently distinfo was not regenerated properly after the last
update, so there's a diff applied to it unrelated to this change set.)


(gutteridge)
diff -r1.135 -r1.136 pkgsrc/textproc/libxml2/distinfo
diff -r0 -r1.4 pkgsrc/textproc/libxml2/patches/patch-python_libxml.c
diff -r1.68 -r1.69 pkgsrc/textproc/py-libxml2/Makefile

cvs diff -r1.135 -r1.136 pkgsrc/textproc/libxml2/distinfo (expand / switch to unified diff)

--- pkgsrc/textproc/libxml2/distinfo 2021/05/23 19:31:47 1.135
+++ pkgsrc/textproc/libxml2/distinfo 2021/06/12 17:02:51 1.136
@@ -1,19 +1,16 @@ @@ -1,19 +1,16 @@
1$NetBSD: distinfo,v 1.135 2021/05/23 19:31:47 nia Exp $ 1$NetBSD: distinfo,v 1.136 2021/06/12 17:02:51 gutteridge Exp $
2 2
3SHA1 (libxml2-2.9.12.tar.gz) = 339fe5bb2a7d0c13f068c26d8f7cd194c13f9a2a 3SHA1 (libxml2-2.9.12.tar.gz) = 339fe5bb2a7d0c13f068c26d8f7cd194c13f9a2a
4RMD160 (libxml2-2.9.12.tar.gz) = 766b9460b9e62b8152f431747c30c88c868c0c7e 4RMD160 (libxml2-2.9.12.tar.gz) = 766b9460b9e62b8152f431747c30c88c868c0c7e
5SHA512 (libxml2-2.9.12.tar.gz) = df1c6486e80f0fcf3c506f3599bcfb94b620c00d0b5d26831bc983daa78d58ec58b5057b1ec7c1a26c694f40199c6234ee2a6dcabf65abfa10c447cb5705abbd 5SHA512 (libxml2-2.9.12.tar.gz) = df1c6486e80f0fcf3c506f3599bcfb94b620c00d0b5d26831bc983daa78d58ec58b5057b1ec7c1a26c694f40199c6234ee2a6dcabf65abfa10c447cb5705abbd
6Size (libxml2-2.9.12.tar.gz) = 5681632 bytes 6Size (libxml2-2.9.12.tar.gz) = 5681632 bytes
7SHA1 (patch-Makefile.in) = e687eaa9805b855b0c8a944ec5c597bd34954472 7SHA1 (patch-Makefile.in) = e687eaa9805b855b0c8a944ec5c597bd34954472
8SHA1 (patch-catalog.c) = 34afe787f6012b460a85be993048e133907a1621 8SHA1 (patch-catalog.c) = 34afe787f6012b460a85be993048e133907a1621
9SHA1 (patch-configure) = f6e9f08377a537657df08deee17a5cc66c60b808 9SHA1 (patch-configure) = f6e9f08377a537657df08deee17a5cc66c60b808
10SHA1 (patch-doc_examples_Makefile.in) = 4eede9719724f94402e850ee6d6043a74aaf62b2 10SHA1 (patch-doc_examples_Makefile.in) = 4eede9719724f94402e850ee6d6043a74aaf62b2
11SHA1 (patch-encoding.c) = 62b3343f0a0ea51e3fb8eb693e495520eefb6ffd 11SHA1 (patch-encoding.c) = 62b3343f0a0ea51e3fb8eb693e495520eefb6ffd
12SHA1 (patch-parser.c) = 9dcda6b8bc71c1abb095fc2c840ac40c1ae04a33 12SHA1 (patch-python_libxml.c) = a8d89922589f51db99c2b8960b32d37ddda8a7a9
13SHA1 (patch-python-types.c) = d3c93a1c68956bc7da4f81a8fcbf1e6bad580bef 
14SHA1 (patch-python_libxml.c) = c092f10787be1bb43764cc0bef4ffd35bbe6ec94 
15SHA1 (patch-python_libxml.py) = 869a72ae5ba2e27e6d46552878890acb22337675 13SHA1 (patch-python_libxml.py) = 869a72ae5ba2e27e6d46552878890acb22337675
16SHA1 (patch-python_libxml2.py) = 209d105b0f3aedb834091390a7c6819705108e34 14SHA1 (patch-python_libxml2.py) = 209d105b0f3aedb834091390a7c6819705108e34
17SHA1 (patch-python_setup.py) = 7771fd02ee6779463f1d3321f099d7e6d19cd1b1 15SHA1 (patch-python_setup.py) = 7771fd02ee6779463f1d3321f099d7e6d19cd1b1
18SHA1 (patch-xmlcatalog.c) = d65b7e3be9694147e96ce4bb70a1739e2279ba81 16SHA1 (patch-xmlcatalog.c) = d65b7e3be9694147e96ce4bb70a1739e2279ba81
19SHA1 (patch-xmlschemas.c) = edd5be08e7b19ab8e35412b854e95dedbb7befdd 

File Added: pkgsrc/textproc/libxml2/patches/Attic/patch-python_libxml.c
$NetBSD: patch-python_libxml.c,v 1.4 2021/06/12 17:02:51 gutteridge Exp $

Avoid returning invalid UTF-8 strings to Python.
Based on https://bugzilla.opensuse.org/attachment.cgi?id=746044&action=edit
Fixes https://github.com/itstool/itstool/issues/22

--- python/libxml.c.orig	2016-06-07 10:04:14.000000000 +0000
+++ python/libxml.c
@@ -1620,6 +1620,7 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNU
     PyObject *message;
     PyObject *result;
     char str[1000];
+    unsigned char *ptr = (unsigned char *)str;
 
 #ifdef DEBUG_ERROR
     printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
@@ -1636,10 +1637,14 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNU
 	    str[999] = 0;
         va_end(ap);
 
+        /* Ensure the error string doesn't start at UTF8 continuation. */
+        while (*ptr && (*ptr & 0xc0) == 0x80)
+	    ptr++;
+
         list = PyTuple_New(2);
         PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt);
         Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
-        message = libxml_charPtrConstWrap(str);
+        message = libxml_charPtrConstWrap(ptr);
         PyTuple_SetItem(list, 1, message);
         result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list);
         Py_XDECREF(list);

cvs diff -r1.68 -r1.69 pkgsrc/textproc/py-libxml2/Makefile (expand / switch to unified diff)

--- pkgsrc/textproc/py-libxml2/Makefile 2021/05/23 19:31:47 1.68
+++ pkgsrc/textproc/py-libxml2/Makefile 2021/06/12 17:02:51 1.69
@@ -1,18 +1,19 @@ @@ -1,18 +1,19 @@
1# $NetBSD: Makefile,v 1.68 2021/05/23 19:31:47 nia Exp $ 1# $NetBSD: Makefile,v 1.69 2021/06/12 17:02:51 gutteridge Exp $
2 2
3.include "../../textproc/libxml2/Makefile.common" 3.include "../../textproc/libxml2/Makefile.common"
4 4
5PKGNAME= ${PYPKGPREFIX}-${DISTNAME} 5PKGNAME= ${PYPKGPREFIX}-${DISTNAME}
 6PKGREVISION= 1
6 7
7COMMENT= Python wrapper for libxml2 8COMMENT= Python wrapper for libxml2
8LICENSE= modified-bsd 9LICENSE= modified-bsd
9 10
10USE_GCC_RUNTIME= yes 11USE_GCC_RUNTIME= yes
11 12
12PYSETUPSUBDIR= python 13PYSETUPSUBDIR= python
13NO_CONFIGURE= YES 14NO_CONFIGURE= YES
14 15
15SUBST_CLASSES+= setup 16SUBST_CLASSES+= setup
16SUBST_MESSAGE.setup= Fixing hardcoded paths. 17SUBST_MESSAGE.setup= Fixing hardcoded paths.
17SUBST_STAGE.setup= pre-build 18SUBST_STAGE.setup= pre-build
18SUBST_FILES.setup= python/setup.py 19SUBST_FILES.setup= python/setup.py