Add back 'ensure 1' to avoid overflowing an output buffer
The counter-example for the existing code is a string of length '2*n' that
starts with 'n' characters with codepoints in the range (0x7F, 0x7FF) and ends
with 'n' ASCII characters. All 'n' ASCII characters will be written after the
end of the output buffer.
commit22dc447be77c6a84d5c2c76361fab11617ca02d5
authorSimon Meier <simon.meier@erudify.com>
dateFri 3 Jan 2014, 22:33 (13 years ago)
parent0f3435b
Data/Text/Encoding.hs+1−1
@@ -384,7 +384,7 @@ encodeUtf8 (Text arr off len) = unsafeDupablePerformIO $ do
384384 start newSize n m fp'
385385 {-# INLINE ensure #-}
386386 case A.unsafeIndex arr n of
387− w| w <= 0x7F -> do
387+ w| w <= 0x7F -> ensure 1 $ do
388388 poke (ptr `plusPtr` m) (fromIntegral w :: Word8)
389389 go (n+1) (m+1)
390390 | w <= 0x7FF -> ensure 2 $ do