[libxml2] Patch for xinclude of text using multibyte characters
- From: Daniel Veillard <veillard src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] Patch for xinclude of text using multibyte characters
- Date: Fri, 17 Aug 2012 15:00:38 +0000 (UTC)
commit dce1c8baaeaa4f23874c59da91d9ecc0e31a787c
Author: Vitaly Ostanin <vitaly ostanin gmail com>
Date: Fri Aug 17 20:42:52 2012 +0800
Patch for xinclude of text using multibyte characters
for bug https://bugzilla.gnome.org/show_bug.cgi?id=633166
When you xinclude a text file, reading portions (by 4000 bytes) of the
buffer incorrectly handled the situation when the end comes across
portions of the bytes in a multibyte character.
xinclude.c | 22 ++++++++++++++++------
1 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/xinclude.c b/xinclude.c
index a42793e..a836958 100644
--- a/xinclude.c
+++ b/xinclude.c
@@ -1801,6 +1801,7 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
xmlCharEncoding enc = (xmlCharEncoding) 0;
xmlParserCtxtPtr pctxt;
xmlParserInputPtr inputStream;
+ int xinclude_multibyte_fallback_used = 0;
/*
* Check the URL and remove any fragment identifier
@@ -1897,6 +1898,7 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
/*
* Scan all chars from the resource and add the to the node
*/
+xinclude_multibyte_fallback:
while (xmlParserInputBufferRead(buf, 128) > 0) {
int len;
const xmlChar *content;
@@ -1909,13 +1911,21 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
cur = xmlStringCurrentChar(NULL, &content[i], &l);
if (!IS_CHAR(cur)) {
- xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
- XML_XINCLUDE_INVALID_CHAR,
- "%s contains invalid char\n", URL);
- xmlFreeParserInputBuffer(buf);
- xmlFree(URL);
- return(-1);
+ /* Handle splitted multibyte char at buffer boundary */
+ if (((len - i) < 4) && (!xinclude_multibyte_fallback_used)) {
+ xinclude_multibyte_fallback_used = 1;
+ xmlBufShrink(buf->buffer, i);
+ goto xinclude_multibyte_fallback;
+ } else {
+ xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
+ XML_XINCLUDE_INVALID_CHAR,
+ "%s contains invalid char\n", URL);
+ xmlFreeParserInputBuffer(buf);
+ xmlFree(URL);
+ return(-1);
+ }
} else {
+ xinclude_multibyte_fallback_used = 0;
xmlNodeAddContentLen(node, &content[i], l);
}
i += l;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]