2
0
Эх сурвалжийг харах

* 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 -

Jonas Maebe 11 жил өмнө
parent
commit
de59d6ac11
1 өөрчлөгдсөн 9 нэмэгдсэн , 1 устгасан
  1. 9 1
      rtl/inc/text.inc

+ 9 - 1
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}