Skip to content

Commit 572ed67

Browse files
committed
Prevent decoding Version higher than 11
1 parent faa7a9d commit 572ed67

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

libs/cardano-ledger-binary/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Version history for `cardano-ledger-binary`
22

3+
## 1.7.1.0
4+
5+
* Disable decoding version `12` and higher.
6+
37
## 1.7.0.0
48

59
* Add `Random` instance for `Version`.

libs/cardano-ledger-binary/cardano-ledger-binary.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.0
22
name: cardano-ledger-binary
3-
version: 1.7.0.0
3+
version: 1.7.1.0
44
license: Apache-2.0
55
maintainer: [email protected]
66
author: IOHK

libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/Decoder.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,10 @@ unlessDecoderVersionAtLeast atLeast decoder = do
425425
--------------------------------------------------------------------------------
426426

427427
decodeVersion :: Decoder s Version
428-
decodeVersion = decodeWord64 >>= mkVersion64
428+
decodeVersion = do
429+
v <- decodeWord64 >>= mkVersion64
430+
when (v >= natVersion @12) $ fail "Version number 12 and higher are not yet supported"
431+
pure v
429432
{-# INLINE decodeVersion #-}
430433

431434
-- | `Decoder` for `Rational`. Versions variance:

libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/Arbitrary.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE DataKinds #-}
23
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
34
{-# LANGUAGE LambdaCase #-}
45
{-# LANGUAGE MultiParamTypeClasses #-}
@@ -205,7 +206,7 @@ deriving instance Arbitrary SystemStart
205206
deriving instance Arbitrary BlockNo
206207

207208
instance Arbitrary Version where
208-
arbitrary = genVersion minBound maxBound
209+
arbitrary = genVersion minBound (natVersion @11)
209210

210211
genVersion :: HasCallStack => Version -> Version -> Gen Version
211212
genVersion minVersion maxVersion =

0 commit comments

Comments
 (0)