1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-12 09:17:37 +03:00

parser: Halt parser on DTD errors

If we try to continue parsing after an error in the internal or external
subset, entity expansion accounting gets more complicated. Simply halt
the parser.

Found with libFuzzer.
This commit is contained in:
Nick Wellnhofer 2023-01-22 13:09:03 +01:00
parent d9a8dab3a3
commit 74aa61e0bd
20 changed files with 4 additions and 201 deletions

View File

@ -7143,7 +7143,8 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID,
xmlParseMarkupDecl(ctxt);
} else {
xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL);
break;
xmlHaltParser(ctxt);
return;
}
SKIP_BLANKS;
}
@ -8481,10 +8482,8 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
"xmlParseInternalSubset: error detected in"
" Markup declaration\n");
if (ctxt->inputNr > baseInputNr)
xmlPopInput(ctxt);
else
break;
xmlHaltParser(ctxt);
return;
}
SKIP_BLANKS;
}

View File

@ -69,20 +69,6 @@ Entity: line 1:
Entity: line 1:
<!ELEMENT root (middle) >
^
{0}/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%defroot; %defmiddle; %deftest;
^
Entity: line 1:
<!ELEMENT middle (test) >
^
{0}/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%defroot; %defmiddle; %deftest;
^
Entity: line 1:
<!ELEMENT test (#PCDATA) >
^
""".format(dir_prefix),
't8a':
"""{0}/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
@ -92,20 +78,6 @@ Entity: line 1:
Entity: line 1:
<!ELEMENT root (middle) >
^
{0}/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%defroot;%defmiddle;%deftest;
^
Entity: line 1:
<!ELEMENT middle (test) >
^
{0}/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%defroot;%defmiddle;%deftest;
^
Entity: line 1:
<!ELEMENT test (#PCDATA) >
^
""".format(dir_prefix),
'xlink':
"""{0}/xlink.xml:450: element termdef: validity error : ID dt-arc already defined

View File

@ -5,13 +5,3 @@
Entity: line 1:
A<lbbbbbbbbbbbbbbbbbbb_
^
./test/errors/754946.xml:4: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
<![
^
./test/errors/754946.xml:4: parser error : DOCTYPE improperly terminated
<![
^
./test/errors/754946.xml:4: parser error : Start tag expected, '<' not found
<![
^

View File

@ -5,13 +5,3 @@
Entity: line 1:
A<lbbbbbbbbbbbbbbbbbbb_
^
./test/errors/754946.xml:4: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
<![
^
./test/errors/754946.xml:4: parser error : DOCTYPE improperly terminated
<![
^
./test/errors/754946.xml:4: parser error : Start tag expected, '<' not found
<![
^

View File

@ -5,11 +5,4 @@
Entity: line 1:
A<lbbbbbbbbbbbbbbbbbbb_
^
./test/errors/754946.xml:4: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
<![
^
./test/errors/754946.xml:4: parser error : DOCTYPE improperly terminated
<![
^
./test/errors/754946.xml : failed to parse

View File

@ -23,13 +23,3 @@ Entity: line 1:
Entity: line 2:
<![INCLUDE[
^
./test/errors/759573-2.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%xx;
^
./test/errors/759573-2.xml:6: parser error : DOCTYPE improperly terminated
%xx;
^
./test/errors/759573-2.xml:6: parser error : Start tag expected, '<' not found
%xx;
^

View File

@ -23,13 +23,3 @@ Entity: line 1:
Entity: line 2:
<![INCLUDE[
^
./test/errors/759573-2.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%xx;
^
./test/errors/759573-2.xml:6: parser error : DOCTYPE improperly terminated
%xx;
^
./test/errors/759573-2.xml:6: parser error : Start tag expected, '<' not found
%xx;
^

View File

@ -23,11 +23,4 @@ Entity: line 1:
Entity: line 2:
<![INCLUDE[
^
./test/errors/759573-2.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%xx;
^
./test/errors/759573-2.xml:6: parser error : DOCTYPE improperly terminated
%xx;
^
./test/errors/759573-2.xml : failed to parse

View File

@ -20,13 +20,3 @@ T t (A)><!ENTITY % xx '&#37;<![INCLUDE[000&#37;&#3000;000&#37;z;'><!ENTITYz>%xx;
Entity: line 1:
%<![INCLUDE[000%ஸ000%z;
^
./test/errors/759573.xml:1: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
T t (A)><!ENTITY % xx '&#37;<![INCLUDE[000&#37;&#3000;000&#37;z;'><!ENTITYz>%xx;
^
./test/errors/759573.xml:1: parser error : DOCTYPE improperly terminated
T t (A)><!ENTITY % xx '&#37;<![INCLUDE[000&#37;&#3000;000&#37;z;'><!ENTITYz>%xx;
^
./test/errors/759573.xml:1: parser error : Start tag expected, '<' not found
T t (A)><!ENTITY % xx '&#37;<![INCLUDE[000&#37;&#3000;000&#37;z;'><!ENTITYz>%xx;
^

View File

@ -20,13 +20,3 @@ T t (A)><!ENTITY % xx '&#37;<![INCLUDE[000&#37;&#3000;000&#37;z;'><!ENTITYz>%xx;
Entity: line 1:
%<![INCLUDE[000%ஸ000%z;
^
./test/errors/759573.xml:1: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
T t (A)><!ENTITY % xx '&#37;<![INCLUDE[000&#37;&#3000;000&#37;z;'><!ENTITYz>%xx;
^
./test/errors/759573.xml:1: parser error : DOCTYPE improperly terminated
T t (A)><!ENTITY % xx '&#37;<![INCLUDE[000&#37;&#3000;000&#37;z;'><!ENTITYz>%xx;
^
./test/errors/759573.xml:1: parser error : Start tag expected, '<' not found
T t (A)><!ENTITY % xx '&#37;<![INCLUDE[000&#37;&#3000;000&#37;z;'><!ENTITYz>%xx;
^

View File

@ -20,11 +20,4 @@ T t (A)><!ENTITY % xx '&#37;<![INCLUDE[000&#37;&#3000;000&#37;z;'><!ENTITYz>%xx;
Entity: line 1:
%<![INCLUDE[000%ஸ000%z;
^
./test/errors/759573.xml:1: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
T t (A)><!ENTITY % xx '&#37;<![INCLUDE[000&#37;&#3000;000&#37;z;'><!ENTITYz>%xx;
^
./test/errors/759573.xml:1: parser error : DOCTYPE improperly terminated
T t (A)><!ENTITY % xx '&#37;<![INCLUDE[000&#37;&#3000;000&#37;z;'><!ENTITYz>%xx;
^
./test/errors/759573.xml : failed to parse

View File

@ -8,9 +8,3 @@
<!ELEMENT aElement (a |b * >
^
./test/errors/content1.xml:7: parser error : DOCTYPE improperly terminated
<!ELEMENT aElement (a |b * >
^
./test/errors/content1.xml:7: parser error : Start tag expected, '<' not found
<!ELEMENT aElement (a |b * >
^

View File

@ -8,9 +8,3 @@
<!ELEMENT aElement (a |b * >
^
./test/errors/content1.xml:7: parser error : DOCTYPE improperly terminated
<!ELEMENT aElement (a |b * >
^
./test/errors/content1.xml:7: parser error : Start tag expected, '<' not found
<!ELEMENT aElement (a |b * >
^

View File

@ -6,9 +6,6 @@
^
./test/errors/content1.xml:7: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
<!ELEMENT aElement (a |b * >
^
./test/errors/content1.xml:7: parser error : DOCTYPE improperly terminated
<!ELEMENT aElement (a |b * >
^
./test/errors/content1.xml : failed to parse

View File

@ -5,13 +5,3 @@
Entity: line 1:
<:0000
^
./test/errors10/781205.xml:4: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
^
./test/errors10/781205.xml:4: parser error : DOCTYPE improperly terminated
^
./test/errors10/781205.xml:4: parser error : Start tag expected, '<' not found
^

View File

@ -4,10 +4,4 @@
./test/errors10/781361.xml:4: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
^
./test/errors10/781361.xml:4: parser error : DOCTYPE improperly terminated
^
./test/errors10/781361.xml:4: parser error : Start tag expected, '<' not found
^

View File

@ -5,17 +5,3 @@
Entity: line 1:
&lt;!ELEMENT root (middle) >
^
./test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%defroot; %defmiddle; %deftest;
^
Entity: line 1:
&lt;!ELEMENT middle (test) >
^
./test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%defroot; %defmiddle; %deftest;
^
Entity: line 1:
&lt;!ELEMENT test (#PCDATA) >
^

View File

@ -5,18 +5,4 @@
Entity: line 1:
&lt;!ELEMENT root (middle) >
^
./test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%defroot; %defmiddle; %deftest;
^
Entity: line 1:
&lt;!ELEMENT middle (test) >
^
./test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%defroot; %defmiddle; %deftest;
^
Entity: line 1:
&lt;!ELEMENT test (#PCDATA) >
^
./test/valid/t8.xml : failed to parse

View File

@ -5,17 +5,3 @@
Entity: line 1:
&lt;!ELEMENT root (middle) >
^
./test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%defroot;%defmiddle;%deftest;
^
Entity: line 1:
&lt;!ELEMENT middle (test) >
^
./test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%defroot;%defmiddle;%deftest;
^
Entity: line 1:
&lt;!ELEMENT test (#PCDATA) >
^

View File

@ -5,18 +5,4 @@
Entity: line 1:
&lt;!ELEMENT root (middle) >
^
./test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%defroot;%defmiddle;%deftest;
^
Entity: line 1:
&lt;!ELEMENT middle (test) >
^
./test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
%defroot;%defmiddle;%deftest;
^
Entity: line 1:
&lt;!ELEMENT test (#PCDATA) >
^
./test/valid/t8a.xml : failed to parse