Fix a bug in `Data.Text.Fusion.mapAccumL` #50

merged 1 commit into from Sep 21, 2013


None yet

2 participants


If the parameter f maps from Chars that fit in a single Word16 to Chars that require two Word16s, it is possible to write to an out-of-bounds index, as demonstrated by the following code:

module Main where

import Data.Char
import qualified Data.Text as T

main = do
  let f a c = (a, chr 65536)
  print . T.mapAccumL f 0 . T.pack $ "aaaaa"

If you run this code with -DASSERTS you'll get an exception. The source of the issue is that in the inner loop of Data.Text.Fusion.mapAccumL, you determine the safety of writing into the array based on the Char passed to f instead of the one it returns.

@bos bos merged commit 64149f2 into bos:master Sep 21, 2013
bos commented Sep 21, 2013

Nice catch, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment