From 896b6c1fd3b842f377d1b62135dccf0a579cf65d Mon Sep 17 00:00:00 2001 From: Don Lewis Date: Fri, 12 Aug 2016 23:40:42 +0200 Subject: [PATCH] Fix utf8_toUtf16 (bug #539) --- expat/lib/xmltok.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/expat/lib/xmltok.c b/expat/lib/xmltok.c index a29d9e2f..b014e72c 100644 --- a/expat/lib/xmltok.c +++ b/expat/lib/xmltok.c @@ -402,7 +402,7 @@ utf8_toUtf16(const ENCODING *enc, case BT_LEAD2: if (fromLim - from < 2) { res = XML_CONVERT_INPUT_INCOMPLETE; - break; + goto after; } *to++ = (unsigned short)(((from[0] & 0x1f) << 6) | (from[1] & 0x3f)); from += 2; @@ -410,7 +410,7 @@ utf8_toUtf16(const ENCODING *enc, case BT_LEAD3: if (fromLim - from < 3) { res = XML_CONVERT_INPUT_INCOMPLETE; - break; + goto after; } *to++ = (unsigned short)(((from[0] & 0xf) << 12) | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f)); @@ -441,6 +441,8 @@ utf8_toUtf16(const ENCODING *enc, break; } } + if (from < fromLim) + res = XML_CONVERT_OUTPUT_EXHAUSTED; after: *fromP = from; *toP = to;