From 60173c821eff9e01f1b8bab4f722150a4c3cf82f Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Tue, 11 Sep 2018 14:08:39 +0200 Subject: [PATCH 24/62] Reset HTML parser input pointers on encoding failure Call xmlBufResetInput before bailing out if switching the encoding fails. Otherwise, the input pointers could be left in an invalid state. Similar to commit f9e7997e803457b714352c4d51a96104ae298d94 for the XML parser. Thanks to Yunho Kim for the report. Closes: #27 --- HTMLparser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HTMLparser.c b/HTMLparser.c index 96a1bf4..9e60e27 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -3636,12 +3636,12 @@ htmlCheckEncodingDirect(htmlParserCtxtPtr ctxt, const xmlChar *encoding) { processed = ctxt->input->cur - ctxt->input->base; xmlBufShrink(ctxt->input->buf->buffer, processed); nbchars = xmlCharEncInput(ctxt->input->buf, 1); + xmlBufResetInput(ctxt->input->buf->buffer, ctxt->input); if (nbchars < 0) { htmlParseErr(ctxt, XML_ERR_INVALID_ENCODING, "htmlCheckEncoding: encoder error\n", NULL, NULL); } - xmlBufResetInput(ctxt->input->buf->buffer, ctxt->input); } } } -- 1.8.3.1