on master help sign in
Test for trying to read negative length with getByteString.

If not checking the requested read length, we're most likely to segfault.

commit0ed38e7ca5633f2a93ea59011f596b964a9d6c94 authorLennart Kolmodin <kolmodin@google.com> dateThu 1 Mar 2012, 22:48 (15 years ago) parent3ab9b9a
1 file changed+10
BitsQC.hs+10
BitsQC.hs+10
@@ -14,6 +14,7 @@ import Data.Binary.Bits.Get
1414import Data.Binary.Bits.Put
1515
1616import qualified Data.ByteString as B
17+import qualified Data.ByteString.Lazy as L
1718
1819import Control.Applicative
1920import Data.Bits
@@ -39,6 +40,9 @@ tests =
3940 , testGroup "Custom test cases"
4041 [ testProperty "prop_composite_case" prop_composite_case ]
4142
43+ , testGroup "getByteString"
44+ [ testProperty "prop_getByteString_negative" prop_getByteString_negative ]
45+
4246 , testGroup "prop_bitput_with_get_from_binary"
4347 [ testProperty "Word8" (prop_bitput_with_get_from_binary :: W [Word8] -> Property)
4448 , testProperty "Word16" (prop_bitput_with_get_from_binary :: W [Word16] -> Property)
@@ -103,6 +107,12 @@ tests =
103107 ]
104108 ]
105109
110+
111+prop_getByteString_negative :: Int -> Property
112+prop_getByteString_negative n =
113+ n < 1 ==>
114+ runGet (runBitGet (getByteString n)) L.empty == B.empty
115+
106116prop_putget_with_bitreq :: (BinaryBit a, Num a, Bits a, Ord a) => W a -> Property
107117prop_putget_with_bitreq (W w) = property $
108118 -- write all words with as many bits as it's required