diff --git a/xinclude.c b/xinclude.c index 2916ffa..b58dc43 100644 --- a/xinclude.c +++ b/xinclude.c @@ -1880,6 +1880,8 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) { /* * Scan all chars from the resource and add the to the node */ + int xinclude_multibyte_fallback_used = 0; +xinclude_multibyte_fallback: while (xmlParserInputBufferRead(buf, 128) > 0) { int len; const xmlChar *content; @@ -1892,13 +1894,21 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) { cur = xmlStringCurrentChar(NULL, &content[i], &l); if (!IS_CHAR(cur)) { + // Handle splitted multibyte char at buffer boundary + if ((len - i) < 4 && !xinclude_multibyte_fallback_used) { + xinclude_multibyte_fallback_used = 1; + xmlBufferShrink(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;