1{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}
3-- Regression tests for specific bugs.
5import Control.Exception (SomeException, handle)
7import qualified Data.ByteString as B
8import qualified Data.ByteString.Lazy as LB
9import qualified Data.Text as T
10import qualified Data.Text.IO as T
11import qualified Data.Text.Lazy as LT
12import qualified Data.Text.Lazy.Encoding as LE
13import qualified Test.Framework as F
14import qualified Test.Framework.Providers.HUnit as F
15import Test.HUnit (assertFailure)
16import TestUtils (withTempFile)
18-- Reported by Michael Snoyman: UTF-8 encoding a large lazy bytestring
19-- caused either a segfault or attempt to allocate a negative number
21lazy_encode_crash = withTempFile $ \ _ h ->
22 LB.hPut h . LE.encodeUtf8 . LT.pack . replicate 100000 $ 'a'
24-- Reported by Pieter Laeremans: attempting to read an incorrectly
25-- encoded file can result in a crash in the RTS (i.e. not merely an
27hGetContents_crash = withTempFile $ \ path h -> do
28 B.hPut h (B.pack [0x78, 0xc4 ,0x0a]) >> hClose h
29 h' <- openFile path ReadMode
31 handle (\(_::SomeException) -> return ()) $
32 T.hGetContents h' >> assertFailure "T.hGetContents should crash"
34-- Reported by Ian Lynagh: attempting to allocate a sufficiently large
35-- string (via either Array.new or Text.replicate) could result in an
37replicate_crash = handle (\(_::SomeException) -> return ()) $
38 T.replicate (2^power) "0123456789abcdef" `seq`
39 assertFailure "T.replicate should crash"
41 power | maxBound == (2147483647::Int) = 28
42 | otherwise = 60 :: Int
45tests = F.testGroup "crashers" [
46 F.testCase "hGetContents_crash" hGetContents_crash
47 , F.testCase "lazy_encode_crash" lazy_encode_crash
48 , F.testCase "replicate_crash" replicate_crash
51main = F.defaultMain [tests]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list