1From 4ad71c2d72beef0d10cf75aa417db10d77846f75 Mon Sep 17 00:00:00 2001 2From: Nick Wellnhofer <wellnhofer@aevum.de> 3Date: Sat, 20 Aug 2022 16:19:34 +0200 4Subject: [PATCH] Fix xmlCtxtReadDoc with encoding 5 6xmlCtxtReadDoc used to create an input stream involving 7xmlNewStringInputStream. This would create a stream without an input 8buffer, causing problems with encodings (see #34). 9 10After commit aab584dc3, an error was returned even with UTF-8 encodings 11which happened to work before. 12 13Make xmlCtxtReadDoc call xmlCtxtReadMemory which doesn't suffer from 14these issues. Also fix htmlCtxtReadDoc. 15 16Fixes #397. 17Reference:https://github.com/GNOME/libxml2/commit/4ad71c2d72beef0d10cf75aa417db10d77846f75 18Conflict:NA 19--- 20 HTMLparser.c | 17 ++++------------- 21 parser.c | 16 +++------------- 22 2 files changed, 7 insertions(+), 26 deletions(-) 23 24diff --git a/HTMLparser.c b/HTMLparser.c 25index 98d73f3..a4168f3 100644 26--- a/HTMLparser.c 27+++ b/HTMLparser.c 28@@ -7087,22 +7087,13 @@ htmlDocPtr 29 htmlCtxtReadDoc(htmlParserCtxtPtr ctxt, const xmlChar * cur, 30 const char *URL, const char *encoding, int options) 31 { 32- xmlParserInputPtr stream; 33+ const char *buf; 34 35 if (cur == NULL) 36 return (NULL); 37- if (ctxt == NULL) 38- return (NULL); 39- xmlInitParser(); 40- 41- htmlCtxtReset(ctxt); 42- 43- stream = xmlNewStringInputStream(ctxt, cur); 44- if (stream == NULL) { 45- return (NULL); 46- } 47- inputPush(ctxt, stream); 48- return (htmlDoRead(ctxt, URL, encoding, options, 1)); 49+ buf = (const char *) cur; 50+ return (htmlCtxtReadMemory(ctxt, buf, strlen(buf), URL, encoding, 51+ options)); 52 } 53 54 /** 55diff --git a/parser.c b/parser.c 56index 6b04bbf..fbeb7af 100644 57--- a/parser.c 58+++ b/parser.c 59@@ -15374,22 +15374,12 @@ xmlDocPtr 60 xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar * cur, 61 const char *URL, const char *encoding, int options) 62 { 63- xmlParserInputPtr stream; 64+ const char *buf; 65 66 if (cur == NULL) 67 return (NULL); 68- if (ctxt == NULL) 69- return (NULL); 70- xmlInitParser(); 71- 72- xmlCtxtReset(ctxt); 73- 74- stream = xmlNewStringInputStream(ctxt, cur); 75- if (stream == NULL) { 76- return (NULL); 77- } 78- inputPush(ctxt, stream); 79- return (xmlDoRead(ctxt, URL, encoding, options, 1)); 80+ buf = (const char *) cur; 81+ return (xmlCtxtReadMemory(ctxt, buf, strlen(buf), URL, encoding, options)); 82 } 83 84 /** 85-- 862.27.0 87 88