1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-24 21:33:51 +03:00

parser: Check for truncated multi-byte sequences

When decoding input data, check whether the "raw" buffer is empty after
parsing the document. Otherwise, the input ends with a truncated
multi-byte sequence which shouldn't be silently ignored.
This commit is contained in:
Nick Wellnhofer 2023-08-08 15:21:37 +02:00
parent 95e81a360c
commit 855818bd2b
5 changed files with 22 additions and 2 deletions

View File

@ -10455,7 +10455,12 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
if (RAW != 0) {
xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
}
} else if ((ctxt->input->buf != NULL) &&
(ctxt->input->buf->encoder != NULL) &&
(!xmlBufIsEmpty(ctxt->input->buf->raw))) {
xmlFatalErrMsg(ctxt, XML_ERR_INVALID_CHAR,
"Truncated multi-byte sequence at EOF\n");
}
ctxt->instate = XML_PARSER_EOF;
}
@ -11686,7 +11691,12 @@ xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size,
if ((ctxt->instate == XML_PARSER_EPILOG) &&
(ctxt->input->cur < ctxt->input->end)) {
xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
}
} else if ((ctxt->input->buf != NULL) &&
(ctxt->input->buf->encoder != NULL) &&
(!xmlBufIsEmpty(ctxt->input->buf->raw))) {
xmlFatalErrMsg(ctxt, XML_ERR_INVALID_CHAR,
"Truncated multi-byte sequence at EOF\n");
}
if (ctxt->instate != XML_PARSER_EOF) {
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
ctxt->sax->endDocument(ctxt->userData);

View File

@ -0,0 +1,3 @@
./test/errors/truncated-utf16.xml:1: parser error : Truncated multi-byte sequence at EOF
<d/>
^

View File

@ -0,0 +1,3 @@
./test/errors/truncated-utf16.xml:1: parser error : Truncated multi-byte sequence at EOF
<d/>
^

View File

@ -0,0 +1,4 @@
./test/errors/truncated-utf16.xml:1: parser error : Truncated multi-byte sequence at EOF
<d/>
^
./test/errors/truncated-utf16.xml : failed to parse

Binary file not shown.