From 1b7df9dcc269dbdb4677d1c2930c7111d73032da Mon Sep 17 00:00:00 2001 From: Paul Cadman Date: Wed, 28 Aug 2024 10:18:21 +0100 Subject: [PATCH] The encoding/decoding size range must be greater than the chunkSize in `byteStringToIntegerBE` --- src/Juvix/Compiler/Nockma/Encoding/ByteString.hs | 1 - test/Nockma/Encoding.hs | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Juvix/Compiler/Nockma/Encoding/ByteString.hs b/src/Juvix/Compiler/Nockma/Encoding/ByteString.hs index eae00f1ad7..f7eaf048a1 100644 --- a/src/Juvix/Compiler/Nockma/Encoding/ByteString.hs +++ b/src/Juvix/Compiler/Nockma/Encoding/ByteString.hs @@ -106,7 +106,6 @@ byteStringToIntegerBE = foldl' go 0 . map (first byteStringChunkToInteger) . chu go :: Integer -> (Integer, Int) -> Integer go acc (i, size) = acc `shiftL` (8 * size) .|. i - -- Split the ByteString into chunks and store their sizes chunkByteString :: ByteString -> [(ByteString, Int)] chunkByteString bs | BS.null bs = [] diff --git a/test/Nockma/Encoding.hs b/test/Nockma/Encoding.hs index ebc7250312..07e0c20b6e 100644 --- a/test/Nockma/Encoding.hs +++ b/test/Nockma/Encoding.hs @@ -9,7 +9,8 @@ import Test.Tasty.Hedgehog propEncodingRoundtrip :: Property propEncodingRoundtrip = property $ do - bs <- forAll (Gen.bytes (Range.linear 0 1000)) + -- The range must be greater than the chunkSize in `byteStringToIntegerBE` + bs <- forAll (Gen.bytes (Range.linear 0 3000)) Encoding.decodeByteString (Encoding.encodeByteString bs) === bs allTests :: TestTree