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

Stop checking attributes for UTF-8 validity

I can't see a reason to check attribute content for UTF-8 validity.
Other parts of the API like xmlNewText have always assumed valid UTF-8
as extra checks only slow down processing.

Besides, setting doc->encoding to "ISO-8859-1" seems pointless, and not
freeing the old encoding would cause a memory leak.

Note that this was last changed in 2008 with commit 6f8611fd which
removed unnecessary encoding/decoding steps. Setting attributes should
be even faster now.

Found by OSS-Fuzz.
This commit is contained in:
Nick Wellnhofer 2021-03-02 13:09:06 +01:00
parent 8446d4593e
commit a6e6498fb1

12
tree.c
View File

@ -1901,12 +1901,6 @@ xmlNewPropInternal(xmlNodePtr node, xmlNsPtr ns,
if (value != NULL) {
xmlNodePtr tmp;
if(!xmlCheckUTF8(value)) {
xmlTreeErr(XML_TREE_NOT_UTF8, (xmlNodePtr) doc,
NULL);
if (doc != NULL)
doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
}
cur->children = xmlNewDocText(doc, value);
cur->last = NULL;
tmp = cur->children;
@ -6945,12 +6939,6 @@ xmlSetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name,
if (value != NULL) {
xmlNodePtr tmp;
if(!xmlCheckUTF8(value)) {
xmlTreeErr(XML_TREE_NOT_UTF8, (xmlNodePtr) node->doc,
NULL);
if (node->doc != NULL)
node->doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
}
prop->children = xmlNewDocText(node->doc, value);
prop->last = NULL;
tmp = prop->children;