From 6974feb0cf30d4201140ae2cf9c311bfdd87a4ff Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sun, 5 Feb 2006 02:43:36 +0000 Subject: [PATCH] fixed the comment streaming bug raised by Graham Bennett added to the * parser.c: fixed the comment streaming bug raised by Graham Bennett * test/badcomment.xml result//badcomment.xml*: added to the regression suite. Daniel --- ChangeLog | 6 ++++++ parser.c | 10 ++++++++-- result/badcomment.xml | 17 +++++++++++++++++ result/badcomment.xml.rde | 21 +++++++++++++++++++++ result/badcomment.xml.rdr | 21 +++++++++++++++++++++ result/badcomment.xml.sax | 24 ++++++++++++++++++++++++ result/badcomment.xml.sax2 | 24 ++++++++++++++++++++++++ result/noent/badcomment.xml | 17 +++++++++++++++++ test/badcomment.xml | 18 ++++++++++++++++++ 9 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 result/badcomment.xml create mode 100644 result/badcomment.xml.rde create mode 100644 result/badcomment.xml.rdr create mode 100644 result/badcomment.xml.sax create mode 100644 result/badcomment.xml.sax2 create mode 100644 result/noent/badcomment.xml create mode 100644 test/badcomment.xml diff --git a/ChangeLog b/ChangeLog index c191347d..647b93f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Feb 5 03:41:39 CET 2006 Daniel Veillard + + * parser.c: fixed the comment streaming bug raised by Graham Bennett + * test/badcomment.xml result//badcomment.xml*: added to the regression + suite. + Fri Feb 3 17:36:41 CET 2006 Kasimier Buchcik * include/libxml/tree.h: Added the xmlDOMWrapCloneNode() to diff --git a/parser.c b/parser.c index 4c996dd3..e36cb978 100644 --- a/parser.c +++ b/parser.c @@ -9838,8 +9838,14 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { } else if ((cur == '<') && (next == '!') && (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-')) { - if ((!terminate) && - (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) + int term; + + if (avail < 4) + goto done; + ctxt->input->cur += 4; + term = xmlParseLookupSequence(ctxt, '-', '-', '>'); + ctxt->input->cur -= 4; + if ((!terminate) && (term < 0)) goto done; xmlParseComment(ctxt); ctxt->instate = XML_PARSER_CONTENT; diff --git a/result/badcomment.xml b/result/badcomment.xml new file mode 100644 index 00000000..6b13c113 --- /dev/null +++ b/result/badcomment.xml @@ -0,0 +1,17 @@ + + +Char* ']]>' Char*)) +']]>' +CDATA sections +| '<!DOCTYPE' +(Char - ('[' | ']'))+ +('[' +simpleDTD* +']')? '>' +doc type declaration +simpleDTD +'<!&como;' +(Char* - +(Char* '&comc;' Char*)) +'&comc;>'--> + diff --git a/result/badcomment.xml.rde b/result/badcomment.xml.rde new file mode 100644 index 00000000..29a3cd1c --- /dev/null +++ b/result/badcomment.xml.rde @@ -0,0 +1,21 @@ +0 1 foo 0 0 +1 14 #text 0 1 + +1 8 #comment 0 1 def='NT-Char' +1 8 #comment 0 1 >Char* ']]>' Char*)) +']]>' +CDATA sections +| '<!DOCTYPE' +(Char - ('[' | ']'))+ +('[' +simpleDTD* +']')? '>' +doc type declaration +simpleDTD +'<!&como;' +(Char* - +(Char* '&comc;' Char*)) +'&comc;>' +1 14 #text 0 1 + +0 15 foo 0 0 diff --git a/result/badcomment.xml.rdr b/result/badcomment.xml.rdr new file mode 100644 index 00000000..29a3cd1c --- /dev/null +++ b/result/badcomment.xml.rdr @@ -0,0 +1,21 @@ +0 1 foo 0 0 +1 14 #text 0 1 + +1 8 #comment 0 1 def='NT-Char' +1 8 #comment 0 1 >Char* ']]>' Char*)) +']]>' +CDATA sections +| '<!DOCTYPE' +(Char - ('[' | ']'))+ +('[' +simpleDTD* +']')? '>' +doc type declaration +simpleDTD +'<!&como;' +(Char* - +(Char* '&comc;' Char*)) +'&comc;>' +1 14 #text 0 1 + +0 15 foo 0 0 diff --git a/result/badcomment.xml.sax b/result/badcomment.xml.sax new file mode 100644 index 00000000..d4093693 --- /dev/null +++ b/result/badcomment.xml.sax @@ -0,0 +1,24 @@ +SAX.setDocumentLocator() +SAX.startDocument() +SAX.startElement(foo) +SAX.characters( +, 1) +SAX.comment( def='NT-Char') +SAX.comment(>Char* ']]>' Char*)) +']]>' +CDATA sections +| '<!DOCTYPE' +(Char - ('[' | ']'))+ +('[' +simpleDTD* +']')? '>' +doc type declaration +simpleDTD +'<!&como;' +(Char* - +(Char* '&comc;' Char*)) +'&comc;>') +SAX.characters( +, 1) +SAX.endElement(foo) +SAX.endDocument() diff --git a/result/badcomment.xml.sax2 b/result/badcomment.xml.sax2 new file mode 100644 index 00000000..08e56221 --- /dev/null +++ b/result/badcomment.xml.sax2 @@ -0,0 +1,24 @@ +SAX.setDocumentLocator() +SAX.startDocument() +SAX.startElementNs(foo, NULL, NULL, 0, 0, 0) +SAX.characters( +, 1) +SAX.comment( def='NT-Char') +SAX.comment(>Char* ']]>' Char*)) +']]>' +CDATA sections +| '<!DOCTYPE' +(Char - ('[' | ']'))+ +('[' +simpleDTD* +']')? '>' +doc type declaration +simpleDTD +'<!&como;' +(Char* - +(Char* '&comc;' Char*)) +'&comc;>') +SAX.characters( +, 1) +SAX.endElementNs(foo, NULL, NULL) +SAX.endDocument() diff --git a/result/noent/badcomment.xml b/result/noent/badcomment.xml new file mode 100644 index 00000000..6b13c113 --- /dev/null +++ b/result/noent/badcomment.xml @@ -0,0 +1,17 @@ + + +Char* ']]>' Char*)) +']]>' +CDATA sections +| '<!DOCTYPE' +(Char - ('[' | ']'))+ +('[' +simpleDTD* +']')? '>' +doc type declaration +simpleDTD +'<!&como;' +(Char* - +(Char* '&comc;' Char*)) +'&comc;>'--> + diff --git a/test/badcomment.xml b/test/badcomment.xml new file mode 100644 index 00000000..147414c7 --- /dev/null +++ b/test/badcomment.xml @@ -0,0 +1,18 @@ + + + +Char* ']]>' Char*)) +']]>' +CDATA sections +| '<!DOCTYPE' +(Char - ('[' | ']'))+ +('[' +simpleDTD* +']')? '>' +doc type declaration +simpleDTD +'<!&como;' +(Char* - +(Char* '&comc;' Char*)) +'&comc;>'--> +