1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-26 00:37:43 +03:00

Don't try to handle namespaces when building HTML documents

Don't try to resolve namespace in xmlSAX2StartElement when parsing
HTML documents. This useless operation could slow down the parser
considerably.

Found by OSS-Fuzz.
This commit is contained in:
Nick Wellnhofer
2020-07-25 17:57:29 +02:00
parent 93ce33c2b8
commit 21ca8829a7

76
SAX2.c
View File

@@ -1663,23 +1663,23 @@ xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
} }
} }
/* if (!ctxt->html) {
* Insert all the defaulted attributes from the DTD especially namespaces /*
*/ * Insert all the defaulted attributes from the DTD especially
if ((!ctxt->html) && * namespaces
((ctxt->myDoc->intSubset != NULL) || */
(ctxt->myDoc->extSubset != NULL))) { if ((ctxt->myDoc->intSubset != NULL) ||
xmlCheckDefaultedAttributes(ctxt, name, prefix, atts); (ctxt->myDoc->extSubset != NULL)) {
} xmlCheckDefaultedAttributes(ctxt, name, prefix, atts);
}
/* /*
* process all the attributes whose name start with "xmlns" * process all the attributes whose name start with "xmlns"
*/ */
if (atts != NULL) { if (atts != NULL) {
i = 0; i = 0;
att = atts[i++]; att = atts[i++];
value = atts[i++]; value = atts[i++];
if (!ctxt->html) {
while ((att != NULL) && (value != NULL)) { while ((att != NULL) && (value != NULL)) {
if ((att[0] == 'x') && (att[1] == 'm') && (att[2] == 'l') && if ((att[0] == 'x') && (att[1] == 'm') && (att[2] == 'l') &&
(att[3] == 'n') && (att[4] == 's')) (att[3] == 'n') && (att[4] == 's'))
@@ -1688,30 +1688,30 @@ xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
att = atts[i++]; att = atts[i++];
value = atts[i++]; value = atts[i++];
} }
} }
}
/* /*
* Search the namespace, note that since the attributes have been * Search the namespace, note that since the attributes have been
* processed, the local namespaces are available. * processed, the local namespaces are available.
*/ */
ns = xmlSearchNs(ctxt->myDoc, ret, prefix); ns = xmlSearchNs(ctxt->myDoc, ret, prefix);
if ((ns == NULL) && (parent != NULL)) if ((ns == NULL) && (parent != NULL))
ns = xmlSearchNs(ctxt->myDoc, parent, prefix); ns = xmlSearchNs(ctxt->myDoc, parent, prefix);
if ((prefix != NULL) && (ns == NULL)) { if ((prefix != NULL) && (ns == NULL)) {
ns = xmlNewNs(ret, NULL, prefix); ns = xmlNewNs(ret, NULL, prefix);
xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
"Namespace prefix %s is not defined\n", "Namespace prefix %s is not defined\n",
prefix, NULL); prefix, NULL);
} }
/* /*
* set the namespace node, making sure that if the default namespace * set the namespace node, making sure that if the default namespace
* is unbound on a parent we simply keep it NULL * is unbound on a parent we simply keep it NULL
*/ */
if ((ns != NULL) && (ns->href != NULL) && if ((ns != NULL) && (ns->href != NULL) &&
((ns->href[0] != 0) || (ns->prefix != NULL))) ((ns->href[0] != 0) || (ns->prefix != NULL)))
xmlSetNs(ret, ns); xmlSetNs(ret, ns);
}
/* /*
* process all the other attributes * process all the other attributes