From de59d6ac1102a642d3088e15d35f1b0c68678272 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Mon, 30 Dec 2013 14:30:56 +0000 Subject: [PATCH] * prevent endless loop when writing an invalid utf-8 sequence longer than 32 bytes using writestr to a unicode/widestring git-svn-id: trunk@26326 - --- rtl/inc/text.inc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rtl/inc/text.inc b/rtl/inc/text.inc index ae046028cc..15b5fc8630 100644 --- a/rtl/inc/text.inc +++ b/rtl/inc/text.inc @@ -2259,7 +2259,15 @@ begin { we did not yet get all bytes of the last code point -> handle everything until the start of this character } if codepointlen>lenfound+1 then - result:=i + if i<>0 then + result:=i + { the buffer is too small to contain the entire utf-8 code point + -> nothing else to do but handle the entire buffer (and end up + with an invalid character) -- since writestr uses the default + buffer size of 32 bytes, this can only happen for invalid utf-8 + encodings } + else + result:=t.bufpos { the last code point is invalid -> handle everything since it can't become valid by adding more bytes; in case it's complete, we also handle everything, of course}