[commit: packages/bytestring] 0.10.4.x, master: Protect against Int overflow in concat (1d3b3fd)

git at git.haskell.org git at git.haskell.org
Fri Jan 23 22:42:28 UTC 2015


Repository : ssh://git@git.haskell.org/bytestring

On branches: 0.10.4.x,master
Link       : http://git.haskell.org/packages/bytestring.git/commitdiff/1d3b3fd7f979d47bf9a4a170db85eb4cf334d5d0

>---------------------------------------------------------------

commit 1d3b3fd7f979d47bf9a4a170db85eb4cf334d5d0
Author: Bryan O'Sullivan <bos at serpentine.com>
Date:   Fri Jun 6 14:24:38 2014 -0700

    Protect against Int overflow in concat
    
    This partially fixes gh-22.


>---------------------------------------------------------------

1d3b3fd7f979d47bf9a4a170db85eb4cf334d5d0
 tests/Regressions.hs | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tests/Regressions.hs b/tests/Regressions.hs
new file mode 100644
index 0000000..29c9f02
--- /dev/null
+++ b/tests/Regressions.hs
@@ -0,0 +1,23 @@
+import Control.Exception (SomeException, handle)
+import Test.HUnit (assertBool, assertEqual, assertFailure)
+import qualified Data.ByteString as B
+import qualified Test.Framework as F
+import qualified Test.Framework.Providers.HUnit as F
+
+-- Try to generate arguments to concat that are big enough to cause an
+-- Int to overflow.
+concat_overflow :: IO ()
+concat_overflow =
+    handle (\(_::SomeException) -> return ()) $
+    B.concat (replicate lsize (B.replicate bsize 0)) `seq`
+    assertFailure "T.replicate should crash"
+  where
+    (lsize, bsize) | maxBound == (2147483647::Int) = (2^14, 2^18)
+                   | otherwise                     = (2^34, 2^29)
+
+tests :: [F.Test]
+tests = [
+    F.testCase "concat_overflow" concat_overflow
+  ]
+
+main = F.defaultMain tests



More information about the ghc-commits mailing list