[libxml2] Don't switch encoding for internal parameter entities



commit 46dc989080d5d6b7854de8fb3cb3de55ecbf0621
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Thu Jun 8 02:24:56 2017 +0200

    Don't switch encoding for internal parameter entities
    
    This is only needed for external entities. Trying to switch the encoding
    for internal entities could also cause a memory leak in recovery mode.

 parser.c          |   54 +++++++++++++++++++++++++++-------------------------
 parserInternals.c |    6 +----
 2 files changed, 29 insertions(+), 31 deletions(-)
---
diff --git a/parser.c b/parser.c
index 0e51223..862f4fb 100644
--- a/parser.c
+++ b/parser.c
@@ -8020,34 +8020,36 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt)
            input = xmlNewEntityInputStream(ctxt, entity);
            if (xmlPushInput(ctxt, input) < 0)
                return;
-            /*
-             * Get the 4 first bytes and decode the charset
-             * if enc != XML_CHAR_ENCODING_NONE
-             * plug some encoding conversion routines.
-             * Note that, since we may have some non-UTF8
-             * encoding (like UTF16, bug 135229), the 'length'
-             * is not known, but we can calculate based upon
-             * the amount of data in the buffer.
-             */
-           GROW
-            if (ctxt->instate == XML_PARSER_EOF)
-                return;
-            if ((ctxt->input->end - ctxt->input->cur)>=4) {
-                start[0] = RAW;
-                start[1] = NXT(1);
-                start[2] = NXT(2);
-                start[3] = NXT(3);
-                enc = xmlDetectCharEncoding(start, 4);
-                if (enc != XML_CHAR_ENCODING_NONE) {
-                    xmlSwitchEncoding(ctxt, enc);
+
+           if (entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) {
+                /*
+                 * Get the 4 first bytes and decode the charset
+                 * if enc != XML_CHAR_ENCODING_NONE
+                 * plug some encoding conversion routines.
+                 * Note that, since we may have some non-UTF8
+                 * encoding (like UTF16, bug 135229), the 'length'
+                 * is not known, but we can calculate based upon
+                 * the amount of data in the buffer.
+                 */
+                GROW
+                if (ctxt->instate == XML_PARSER_EOF)
+                    return;
+                if ((ctxt->input->end - ctxt->input->cur)>=4) {
+                    start[0] = RAW;
+                    start[1] = NXT(1);
+                    start[2] = NXT(2);
+                    start[3] = NXT(3);
+                    enc = xmlDetectCharEncoding(start, 4);
+                    if (enc != XML_CHAR_ENCODING_NONE) {
+                        xmlSwitchEncoding(ctxt, enc);
+                    }
                 }
-            }
 
-           if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) &&
-               (CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) &&
-               (IS_BLANK_CH(NXT(5)))) {
-               xmlParseTextDecl(ctxt);
-           }
+                if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) &&
+                    (IS_BLANK_CH(NXT(5)))) {
+                    xmlParseTextDecl(ctxt);
+                }
+            }
        }
     }
     ctxt->hasPErefs = 1;
diff --git a/parserInternals.c b/parserInternals.c
index 0270f06..c3300ae 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -1244,11 +1244,7 @@ xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
            input->buf->rawconsumed += use - xmlBufUse(input->buf->raw);
         }
         return (0);
-    } else if (input->length == 0) {
-       /*
-        * When parsing a static memory array one must know the
-        * size to be able to convert the buffer.
-        */
+    } else {
        xmlErrInternal(ctxt, "switching encoding : no input\n", NULL);
        return (-1);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]