Subject: [PATCH] [alpine-aports] [PATCH] main/libxml2 Fix length-related XHTML parsing errors

From: Pavlo Khudolieiev <[email-masked]>
Date: Wed, 7 Nov 2018 11:53:55 +0200

Fix from this commit https://github.com/GNOME/libxml2/commit/7a1bd7f6497ac33a9023d556f6f47a48f01deac0
Revert "Change calls to xmlCharEncInput to set flush false"
This commit broke decoding of larger documents with ICU.
---
 main/libxml2/APKBUILD                         |  4 +-
 .../Length-related-XHTML-parsing-errors.patch | 63 +++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 main/libxml2/Length-related-XHTML-parsing-errors.patch

diff --git a/main/libxml2/APKBUILD b/main/libxml2/APKBUILD
index 46be8fedf7..2093e94e49 100644
--- a/main/libxml2/APKBUILD
+++ b/main/libxml2/APKBUILD
@@ -16,6 +16,7 @@ options="!strip"
 source="http://xmlsoft.org/sources/$pkgname-$pkgver.tar.gz
 	CVE-2018-9251-CVE-2018-14567.patch
 	CVE-2018-14404.patch
+	Length-related-XHTML-parsing-errors.patch
 	"
 builddir="$srcdir/$pkgname-$pkgver"
 
@@ -112,4 +113,5 @@ utils() {
 
 sha512sums="28903282c7672206effa1362fd564cbe4cf5be44264b083a7d14e383f73bccd1b81bcafb5f4f2f56f5e7e05914c660e27668c9ce91b1b9f256ef5358d55ba917  libxml2-2.9.8.tar.gz
 31f6cd6650b05cdd95455fd72927ef6b1f1d23ca4d8d5f776ee83277d670363dfe6bdd2c1330e8f9131212456dece2595b16868fc01f0ab750009b0a007eb513  CVE-2018-9251-CVE-2018-14567.patch
-c273b88d26e475e8a7f73e92ce9a77b1025f3704f11aa129c867e08424d32f1d7d81f4a2991d0cef28db4b8e122c6b356097be24b4651ef1b5a040a466bdcd13  CVE-2018-14404.patch"
+c273b88d26e475e8a7f73e92ce9a77b1025f3704f11aa129c867e08424d32f1d7d81f4a2991d0cef28db4b8e122c6b356097be24b4651ef1b5a040a466bdcd13  CVE-2018-14404.patch
+939a7acd13014766b218d61256b7ac72279618f8831095f708f4713e080f45ab9d922846479d01f9995b8799bc24c38b5b73548968764d7315b6ffc9d3dc547a  Length-related-XHTML-parsing-errors.patch"
diff --git a/main/libxml2/Length-related-XHTML-parsing-errors.patch b/main/libxml2/Length-related-XHTML-parsing-errors.patch
new file mode 100644
index 0000000000..7a4363198e
--- /dev/null
+++ b/main/libxml2/Length-related-XHTML-parsing-errors.patch
@@ -0,0 +1,63 @@
+From 7a1bd7f6497ac33a9023d556f6f47a48f01deac0 Mon Sep 17 00:00:00 2001
+From: Nick Wellnhofer <[email-masked]>
+Date: Sat, 17 Mar 2018 00:03:24 +0100
+Subject: [PATCH] Revert "Change calls to xmlCharEncInput to set flush false"
+
+This reverts commit 6e6ae5daa6cd9640c9a83c1070896273e9b30d14 which
+broke decoding of larger documents with ICU.
+
+See https://bugs.chromium.org/p/chromium/issues/detail?id=820163
+---
+ HTMLparser.c      | 2 +-
+ parserInternals.c | 2 +-
+ xmlIO.c           | 4 ++--
+ 3 files changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/HTMLparser.c b/HTMLparser.c
+index 9adeb174..7e243e60 100644
+--- a/HTMLparser.c
++++ b/HTMLparser.c
+@@ -3635,7 +3635,7 @@ htmlCheckEncodingDirect(htmlParserCtxtPtr ctxt, const xmlChar *encoding) {
+ 	     */
+ 	    processed = ctxt->input->cur - ctxt->input->base;
+ 	    xmlBufShrink(ctxt->input->buf->buffer, processed);
+-	    nbchars = xmlCharEncInput(ctxt->input->buf, 0);
++	    nbchars = xmlCharEncInput(ctxt->input->buf, 1);
+ 	    if (nbchars < 0) {
+ 		htmlParseErr(ctxt, XML_ERR_INVALID_ENCODING,
+ 		             "htmlCheckEncoding: encoder error\n",
+diff --git a/parserInternals.c b/parserInternals.c
+index 8c0cd57a..09876ab4 100644
+--- a/parserInternals.c
++++ b/parserInternals.c
+@@ -1214,7 +1214,7 @@ xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
+                 /*
+                  * convert as much as possible of the buffer
+                  */
+-                nbchars = xmlCharEncInput(input->buf, 0);
++                nbchars = xmlCharEncInput(input->buf, 1);
+             } else {
+                 /*
+                  * convert just enough to get
+diff --git a/xmlIO.c b/xmlIO.c
+index 82543477..f61dd05a 100644
+--- a/xmlIO.c
++++ b/xmlIO.c
+@@ -3157,7 +3157,7 @@ xmlParserInputBufferPush(xmlParserInputBufferPtr in,
+ 	 * convert as much as possible to the parser reading buffer.
+ 	 */
+ 	use = xmlBufUse(in->raw);
+-	nbchars = xmlCharEncInput(in, 0);
++	nbchars = xmlCharEncInput(in, 1);
+ 	if (nbchars < 0) {
+ 	    xmlIOErr(XML_IO_ENCODER, NULL);
+ 	    in->error = XML_IO_ENCODER;
+@@ -3273,7 +3273,7 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) {
+ 	 * convert as much as possible to the parser reading buffer.
+ 	 */
+ 	use = xmlBufUse(in->raw);
+-	nbchars = xmlCharEncInput(in, 0);
++	nbchars = xmlCharEncInput(in, 1);
+ 	if (nbchars < 0) {
+ 	    xmlIOErr(XML_IO_ENCODER, NULL);
+ 	    in->error = XML_IO_ENCODER;
\ No newline at end of file
-- 
2.17.1

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---