1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-23 01:52:48 +03:00

parser: Account for full size of non-well-formed entities

Account for the full size of the entity if parsing stops because of
errors. In our cost model, we have to assume that the entity loader
processes the whole entity regardless of its content.
This commit is contained in:
Nick Wellnhofer
2024-01-07 14:30:57 +01:00
parent 29beef653c
commit 6dc2fdb2bd

View File

@@ -2395,9 +2395,21 @@ xmlPopPE(xmlParserCtxtPtr ctxt) {
ent->flags &= ~XML_ENT_EXPANDING;
if ((ent->flags & XML_ENT_CHECKED) == 0) {
int result;
/*
* Read the rest of the stream in case of errors. We want
* to account for the whole entity size.
*/
do {
ctxt->input->cur = ctxt->input->end;
xmlParserShrink(ctxt);
result = xmlParserGrow(ctxt);
} while (result > 0);
consumed = ctxt->input->consumed;
xmlSaturatedAddSizeT(&consumed,
ctxt->input->cur - ctxt->input->base);
ctxt->input->end - ctxt->input->base);
xmlSaturatedAdd(&ent->expandedSize, consumed);
@@ -11976,6 +11988,7 @@ xmlCtxtParseContent(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
xmlNodePtr root = NULL;
xmlNodePtr list = NULL;
xmlChar *rootName = BAD_CAST "#root";
int result;
if (buildTree) {
root = xmlNewDocNode(ctxt->myDoc, NULL, rootName, NULL);
@@ -12040,6 +12053,16 @@ xmlCtxtParseContent(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
}
}
/*
* Read the rest of the stream in case of errors. We want
* to account for the whole entity size.
*/
do {
ctxt->input->cur = ctxt->input->end;
xmlParserShrink(ctxt);
result = xmlParserGrow(ctxt);
} while (result > 0);
if (buildTree)
nodePop(ctxt);
@@ -12129,7 +12152,7 @@ xmlCtxtParseEntity(xmlParserCtxtPtr ctxt, xmlEntityPtr ent) {
* Entity size accounting
*/
consumed = input->consumed;
xmlSaturatedAddSizeT(&consumed, input->cur - input->base);
xmlSaturatedAddSizeT(&consumed, input->end - input->base);
if ((ent->flags & XML_ENT_CHECKED) == 0)
xmlSaturatedAdd(&ent->expandedSize, consumed);