1
0
mirror of https://github.com/GNOME/libxml2.git synced 2025-10-16 06:16:27 +08:00

parser: Fix handling of invalid char refs in recovery mode

Revert to the old behavior which handles invalid char refs more
gracefully. Probably regressed with 37c6618b (version 2.13.0).
This commit is contained in:
Nick Wellnhofer
2025-07-09 13:10:31 +02:00
parent 6c796b3792
commit bd9d5e39ec
2 changed files with 22 additions and 4 deletions

View File

@@ -2628,14 +2628,13 @@ xmlParseCharRef(xmlParserCtxt *ctxt) {
xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
"xmlParseCharRef: character reference out of bounds\n",
val);
} else if (IS_CHAR(val)) {
return(val);
} else {
val = 0xFFFD;
} else if (!IS_CHAR(val)) {
xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
"xmlParseCharRef: invalid xmlChar value %d\n",
val);
}
return(0);
return(val);
}
/**

View File

@@ -183,6 +183,24 @@ testUndeclEntInContent(void) {
return err;
}
static int
testInvalidCharRecovery(void) {
const char *xml = "<doc>&#x10;</doc>";
xmlDoc *doc;
int err = 0;
doc = xmlReadDoc(BAD_CAST xml, NULL, NULL, XML_PARSE_RECOVER);
if (strcmp((char *) doc->children->children->content, "\x10") != 0) {
fprintf(stderr, "Failed to recover from invalid char ref\n");
err = 1;
}
xmlFreeDoc(doc);
return err;
}
#ifdef LIBXML_VALID_ENABLED
static void
testSwitchDtdExtSubset(void *vctxt, const xmlChar *name ATTRIBUTE_UNUSED,
@@ -1409,6 +1427,7 @@ main(void) {
err |= testNodeGetContent();
err |= testCFileIO();
err |= testUndeclEntInContent();
err |= testInvalidCharRecovery();
#ifdef LIBXML_VALID_ENABLED
err |= testSwitchDtd();
#endif