Skip to content

Commit

Permalink
The encoding/decoding size range must be greater than the chunkSize i…
Browse files Browse the repository at this point in the history
…n `byteStringToIntegerBE`
  • Loading branch information
paulcadman committed Aug 30, 2024
1 parent e146f0a commit 1b7df9d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/Juvix/Compiler/Nockma/Encoding/ByteString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
3 changes: 2 additions & 1 deletion test/Nockma/Encoding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b7df9d

Please sign in to comment.