leb128-cereal 1.0 → 1.1
raw patch · 3 files changed
+11/−1 lines, 3 files
Files
- CHANGELOG.md +4/−0
- leb128-cereal.cabal +1/−1
- src/Data/Serialize/LEB128.hs +6/−0
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for leb128-serialize +## 1.1 -- 2020-06-08++* Fix check for overlong encodings; it was not strict enough+ ## 1.0 -- 2020-04-23 * First version. Released on an unsuspecting world.
leb128-cereal.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: leb128-cereal-version: 1.0+version: 1.1 synopsis: LEB128 and SLEB128 encoding description: This module implements encoding and decoding of 'Natural' and 'Integer'
src/Data/Serialize/LEB128.hs view
@@ -182,6 +182,9 @@ go !shift !w = do byte <- G.getWord8 <|> fail "short encoding" let !byteVal = fromIntegral (clearBit byte 7)+ case bitSizeMaybe w of+ Just bs | shift > bs -> fail "overflow"+ _ -> return () when (isFinite @a) $ unless (byteVal `unsafeShiftL` shift `unsafeShiftR` shift == byteVal) $ fail "overflow"@@ -211,6 +214,9 @@ go !prev !shift !w = do byte <- G.getWord8 <|> fail "short encoding" let !byteVal = fromIntegral (clearBit byte 7)+ case bitSizeMaybe w of+ Just bs | shift > bs -> fail "overflow"+ _ -> return () when (isFinite @a) $ unless ((byteVal `unsafeShiftL` shift `unsafeShiftR` shift) .&. 0x7f == byteVal) $ fail "overflow"