diff --git a/parser.c b/parser.c index 2ebc3799..53d77775 100644 --- a/parser.c +++ b/parser.c @@ -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); diff --git a/result/errors/truncated-utf16.xml.ent b/result/errors/truncated-utf16.xml.ent new file mode 100644 index 00000000..f5be53cb --- /dev/null +++ b/result/errors/truncated-utf16.xml.ent @@ -0,0 +1,3 @@ +./test/errors/truncated-utf16.xml:1: parser error : Truncated multi-byte sequence at EOF + + ^ diff --git a/result/errors/truncated-utf16.xml.err b/result/errors/truncated-utf16.xml.err new file mode 100644 index 00000000..f5be53cb --- /dev/null +++ b/result/errors/truncated-utf16.xml.err @@ -0,0 +1,3 @@ +./test/errors/truncated-utf16.xml:1: parser error : Truncated multi-byte sequence at EOF + + ^ diff --git a/result/errors/truncated-utf16.xml.str b/result/errors/truncated-utf16.xml.str new file mode 100644 index 00000000..e45c5788 --- /dev/null +++ b/result/errors/truncated-utf16.xml.str @@ -0,0 +1,4 @@ +./test/errors/truncated-utf16.xml:1: parser error : Truncated multi-byte sequence at EOF + + ^ +./test/errors/truncated-utf16.xml : failed to parse diff --git a/test/errors/truncated-utf16.xml b/test/errors/truncated-utf16.xml new file mode 100644 index 00000000..b755ddd4 Binary files /dev/null and b/test/errors/truncated-utf16.xml differ