Blame SOURCES/libxml2-Avoid-processing-entities-after-encoding-conversion-failures.patch

6dedca
From 7c2be3213eeddd202c3e4c600cf3cfac06fb128a Mon Sep 17 00:00:00 2001
6dedca
From: Daniel Veillard <veillard@redhat.com>
6dedca
Date: Mon, 9 Nov 2015 18:07:18 +0800
6dedca
Subject: [PATCH] Avoid processing entities after encoding conversion failures
6dedca
To: libvir-list@redhat.com
6dedca
6dedca
For https://bugzilla.gnome.org/show_bug.cgi?id=756527
6dedca
and was also raised by Chromium team in the past
6dedca
6dedca
When we hit a convwersion failure when switching encoding
6dedca
it is bestter to stop parsing there, this was treated as a
6dedca
fatal error but the parser was continuing to process to extract
6dedca
more errors, unfortunately that makes little sense as the data
6dedca
is obviously corrupt and can potentially lead to unexpected behaviour.
6dedca
6dedca
Signed-off-by: Daniel Veillard <veillard@redhat.com>
6dedca
---
6dedca
 parser.c          |  7 +++++--
6dedca
 parserInternals.c | 11 ++++++++++-
6dedca
 2 files changed, 15 insertions(+), 3 deletions(-)
6dedca
6dedca
diff --git a/parser.c b/parser.c
6dedca
index 262db1e..134ea7f 100644
6dedca
--- a/parser.c
6dedca
+++ b/parser.c
6dedca
@@ -10598,7 +10598,8 @@ xmlParseXMLDecl(xmlParserCtxtPtr ctxt) {
6dedca
 	xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, "Blank needed here\n");
6dedca
     }
6dedca
     xmlParseEncodingDecl(ctxt);
6dedca
-    if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
6dedca
+    if ((ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) ||
6dedca
+         (ctxt->instate == XML_PARSER_EOF)) {
6dedca
 	/*
6dedca
 	 * The XML REC instructs us to stop parsing right here
6dedca
 	 */
6dedca
@@ -10722,6 +10723,7 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
6dedca
 
6dedca
     if (CUR == 0) {
6dedca
 	xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL);
6dedca
+	return(-1);
6dedca
     }
6dedca
 
6dedca
     /*
6dedca
@@ -10739,7 +10741,8 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
6dedca
 	 * Note that we will switch encoding on the fly.
6dedca
 	 */
6dedca
 	xmlParseXMLDecl(ctxt);
6dedca
-	if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
6dedca
+	if ((ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) ||
6dedca
+	    (ctxt->instate == XML_PARSER_EOF)) {
6dedca
 	    /*
6dedca
 	     * The XML REC instructs us to stop parsing right here
6dedca
 	     */
6dedca
diff --git a/parserInternals.c b/parserInternals.c
6dedca
index f8a7041..9acfea4 100644
6dedca
--- a/parserInternals.c
6dedca
+++ b/parserInternals.c
6dedca
@@ -937,6 +937,7 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
6dedca
 {
6dedca
     xmlCharEncodingHandlerPtr handler;
6dedca
     int len = -1;
6dedca
+    int ret;
6dedca
 
6dedca
     if (ctxt == NULL) return(-1);
6dedca
     switch (enc) {
6dedca
@@ -1097,7 +1098,15 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
6dedca
     if (handler == NULL)
6dedca
 	return(-1);
6dedca
     ctxt->charset = XML_CHAR_ENCODING_UTF8;
6dedca
-    return(xmlSwitchToEncodingInt(ctxt, handler, len));
6dedca
+    ret = xmlSwitchToEncodingInt(ctxt, handler, len);
6dedca
+    if ((ret < 0) || (ctxt->errNo == XML_I18N_CONV_FAILED)) {
6dedca
+        /*
6dedca
+	 * on encoding conversion errors, stop the parser
6dedca
+	 */
6dedca
+        xmlStopParser(ctxt);
6dedca
+	ctxt->errNo = XML_I18N_CONV_FAILED;
6dedca
+    }
6dedca
+    return(ret);
6dedca
 }
6dedca
 
6dedca
 /**
6dedca
-- 
6dedca
2.5.0
6dedca