[libxml2] xmlTextReader bails too quickly on error



commit 9d9685ad88c17d35b6688695af3ceba7c7309b13
Author: Andy Lutomirski <luto mit edu>
Date:   Tue May 15 20:10:25 2012 +0800

    xmlTextReader bails too quickly on error
    
    For https://bugzilla.gnome.org/show_bug.cgi?id=654567
    I use xmlTextReader to parse failed that might be incomplete.  These files are
    the beginning of a well-formed file, but the end is missing so the file as a
    whole is not well-formed.
    
    The problem is that xmlTextReader starts returning errors when it encounters
    the early EOF, even though I haven't finished reading all of the valid data in
    the file.  It would be helpful if xmlTextReader kept working until the very
    end.

 xmlreader.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/xmlreader.c b/xmlreader.c
index c5ab60e..77ac71b 100644
--- a/xmlreader.c
+++ b/xmlreader.c
@@ -855,16 +855,18 @@ xmlTextReaderPushData(xmlTextReaderPtr reader) {
 		          (const char *) &inbuf->content[reader->cur],
 			  CHUNK_SIZE, 0);
 	    reader->cur += CHUNK_SIZE;
-	    if ((val != 0) || (reader->ctxt->wellFormed == 0))
-		return(-1);
+	    if (val != 0)
+		reader->ctxt->wellFormed = 0;
+	    if (reader->ctxt->wellFormed == 0)
+		break;
 	} else {
 	    s = inbuf->use - reader->cur;
 	    val = xmlParseChunk(reader->ctxt,
 		          (const char *) &inbuf->content[reader->cur],
 			  s, 0);
 	    reader->cur += s;
-	    if ((val != 0) || (reader->ctxt->wellFormed == 0))
-		return(-1);
+	    if (val != 0)
+		reader->ctxt->wellFormed = 0;
 	    break;
 	}
     }
@@ -896,11 +898,17 @@ xmlTextReaderPushData(xmlTextReaderPtr reader) {
 		    s, 1);
 	    reader->cur = inbuf->use;
 	    reader->state  = XML_TEXTREADER_DONE;
-	    if ((val != 0) || (reader->ctxt->wellFormed == 0))
-	        return(-1);
+	    if (val != 0) {
+	        if (reader->ctxt->wellFormed)
+		    reader->ctxt->wellFormed = 0;
+		else
+		    return(-1);
+	    }
 	}
     }
     reader->state = oldstate;
+    if (reader->ctxt->wellFormed == 0)
+	reader->mode = XML_TEXTREADER_MODE_EOF;
     return(0);
 }
 
@@ -1265,8 +1273,6 @@ xmlTextReaderRead(xmlTextReaderPtr reader) {
         return(xmlTextReaderReadTree(reader));
     if (reader->ctxt == NULL)
 	return(-1);
-    if (reader->ctxt->wellFormed != 1)
-	return(-1);
 
 #ifdef DEBUG_READER
     fprintf(stderr, "\nREAD ");



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