@@ -1,4 +1,4 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
1+{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}
22
33-- Regression tests for specific bugs.
44
@@ -6,6 +6,7 @@ import Control.Exception (SomeException, handle)
66import System.IO
77import qualified Data.ByteString as B
88import qualified Data.ByteString.Lazy as LB
9+import qualified Data.Text as T
910import qualified Data.Text.IO as T
1011import qualified Data.Text.Lazy as LT
1112import qualified Data.Text.Lazy.Encoding as LE
@@ -30,10 +31,21 @@ hGetContents_crash = withTempFile $ \ path h -> do
3031 handle (\(_::SomeException) -> return ()) $
3132 T.hGetContents h' >> assertFailure "T.hGetContents should crash"
3233
34+-- Reported by Ian Lynagh: attempting to allocate a sufficiently large
35+-- string (via either Array.new or Text.replicate) could result in an
36+-- integer overflow.
37+replicate_crash = handle (\(_::SomeException) -> return ()) $
38+ T.replicate (2^power) "0123456789abcdef" `seq`
39+ assertFailure "T.replicate should crash"
40+ where
41+ power | maxBound == (2147483647::Int) = 28
42+ | otherwise = 60 :: Int
43+
3344tests :: F.Test
3445tests = F.testGroup "crashers" [
3546 F.testCase "hGetContents_crash" hGetContents_crash
3647 , F.testCase "lazy_encode_crash" lazy_encode_crash
48+ , F.testCase "replicate_crash" replicate_crash
3749 ]
3850
3951main = F.defaultMain [tests]