[libxml2] 444994 HTML chunked failure for attribute with <>



commit eeb9932990528a2746deebac26d0affdd55245f3
Author: Daniel Veillard <veillard redhat com>
Date:   Tue Aug 25 14:42:16 2009 +0200

    444994 HTML chunked failure for attribute with <>
    
    * HTMLparser.c: fix htmlParseLookupSequence to not save ctxt->checkIndex
      when the current buffer ends within an attribute value, as this
      information would be missed in next pass.

 HTMLparser.c |  158 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 85 insertions(+), 73 deletions(-)
---
diff --git a/HTMLparser.c b/HTMLparser.c
index d06724c..ceb47fa 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -4632,7 +4632,8 @@ htmlCreateDocParserCtxt(const xmlChar *cur, const char *encoding) {
 static int
 htmlParseLookupSequence(htmlParserCtxtPtr ctxt, xmlChar first,
                         xmlChar next, xmlChar third, int iscomment,
-						int ignoreattrval) {
+                        int ignoreattrval)
+{
     int base, len;
     htmlParserInputPtr in;
     const xmlChar *buf;
@@ -4641,94 +4642,105 @@ htmlParseLookupSequence(htmlParserCtxtPtr ctxt, xmlChar first,
     char valdellim = 0x0;
 
     in = ctxt->input;
-    if (in == NULL) return(-1);
+    if (in == NULL)
+        return (-1);
+
     base = in->cur - in->base;
-    if (base < 0) return(-1);
+    if (base < 0)
+        return (-1);
+
     if (ctxt->checkIndex > base)
         base = ctxt->checkIndex;
+
     if (in->buf == NULL) {
-	buf = in->base;
-	len = in->length;
+        buf = in->base;
+        len = in->length;
     } else {
-	buf = in->buf->buffer->content;
-	len = in->buf->buffer->use;
+        buf = in->buf->buffer->content;
+        len = in->buf->buffer->use;
     }
+
     /* take into account the sequence length */
-    if (third) len -= 2;
-    else if (next) len --;
-    for (;base < len;base++) {
-	if (!incomment && (base + 4 < len) && !iscomment) {
-	    if ((buf[base] == '<') && (buf[base + 1] == '!') &&
-		(buf[base + 2] == '-') && (buf[base + 3] == '-')) {
-		incomment = 1;
-		/* do not increment past <! - some people use <!--> */
-		base += 2;
-	    }
-	}
-	if (ignoreattrval) {
-		if (buf[base] == '"' || buf[base] == '\'') {
-			if (invalue) {
-				if (buf[base] == valdellim) {
-					invalue = 0;
-					continue;
-				}
-			} else {
-				valdellim = buf[base];
-				invalue = 1;
-				continue;
-			}
-		} else if (invalue) {
-			continue;
-		}
-	}
-	if (incomment) {
-	    if (base + 3 > len)
-		return(-1);
-	    if ((buf[base] == '-') && (buf[base + 1] == '-') &&
-		(buf[base + 2] == '>')) {
-		incomment = 0;
-		base += 2;
-	    }
-	    continue;
-	}
+    if (third)
+        len -= 2;
+    else if (next)
+        len--;
+    for (; base < len; base++) {
+        if ((!incomment) && (base + 4 < len) && (!iscomment)) {
+            if ((buf[base] == '<') && (buf[base + 1] == '!') &&
+                (buf[base + 2] == '-') && (buf[base + 3] == '-')) {
+                incomment = 1;
+                /* do not increment past <! - some people use <!--> */
+                base += 2;
+            }
+        }
+        if (ignoreattrval) {
+            if (buf[base] == '"' || buf[base] == '\'') {
+                if (invalue) {
+                    if (buf[base] == valdellim) {
+                        invalue = 0;
+                        continue;
+                    }
+                } else {
+                    valdellim = buf[base];
+                    invalue = 1;
+                    continue;
+                }
+            } else if (invalue) {
+                continue;
+            }
+        }
+        if (incomment) {
+            if (base + 3 > len)
+                return (-1);
+            if ((buf[base] == '-') && (buf[base + 1] == '-') &&
+                (buf[base + 2] == '>')) {
+                incomment = 0;
+                base += 2;
+            }
+            continue;
+        }
         if (buf[base] == first) {
-	    if (third != 0) {
-		if ((buf[base + 1] != next) ||
-		    (buf[base + 2] != third)) continue;
-	    } else if (next != 0) {
-		if (buf[base + 1] != next) continue;
-	    }
-	    ctxt->checkIndex = 0;
+            if (third != 0) {
+                if ((buf[base + 1] != next) || (buf[base + 2] != third))
+                    continue;
+            } else if (next != 0) {
+                if (buf[base + 1] != next)
+                    continue;
+            }
+            ctxt->checkIndex = 0;
 #ifdef DEBUG_PUSH
-	    if (next == 0)
-		xmlGenericError(xmlGenericErrorContext,
-			"HPP: lookup '%c' found at %d\n",
-			first, base);
-	    else if (third == 0)
-		xmlGenericError(xmlGenericErrorContext,
-			"HPP: lookup '%c%c' found at %d\n",
-			first, next, base);
-	    else
-		xmlGenericError(xmlGenericErrorContext,
-			"HPP: lookup '%c%c%c' found at %d\n",
-			first, next, third, base);
+            if (next == 0)
+                xmlGenericError(xmlGenericErrorContext,
+                                "HPP: lookup '%c' found at %d\n",
+                                first, base);
+            else if (third == 0)
+                xmlGenericError(xmlGenericErrorContext,
+                                "HPP: lookup '%c%c' found at %d\n",
+                                first, next, base);
+            else
+                xmlGenericError(xmlGenericErrorContext,
+                                "HPP: lookup '%c%c%c' found at %d\n",
+                                first, next, third, base);
 #endif
-	    return(base - (in->cur - in->base));
-	}
+            return (base - (in->cur - in->base));
+        }
     }
-    ctxt->checkIndex = base;
+    if ((!incomment) && (!invalue))
+        ctxt->checkIndex = base;
 #ifdef DEBUG_PUSH
     if (next == 0)
-	xmlGenericError(xmlGenericErrorContext,
-		"HPP: lookup '%c' failed\n", first);
+        xmlGenericError(xmlGenericErrorContext,
+                        "HPP: lookup '%c' failed\n", first);
     else if (third == 0)
-	xmlGenericError(xmlGenericErrorContext,
-		"HPP: lookup '%c%c' failed\n", first, next);
+        xmlGenericError(xmlGenericErrorContext,
+                        "HPP: lookup '%c%c' failed\n", first, next);
     else
-	xmlGenericError(xmlGenericErrorContext,
-		"HPP: lookup '%c%c%c' failed\n", first, next, third);
+        xmlGenericError(xmlGenericErrorContext,
+                        "HPP: lookup '%c%c%c' failed\n", first, next,
+                        third);
 #endif
-    return(-1);
+    return (-1);
 }
 
 /**



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