well-typed / cborg

Binary serialisation in the CBOR format
https://hackage.haskell.org/package/cborg
191 stars 86 forks source link

Bignum decoding doesn't allow indefinite-length bytestrings #263

Open michaelpj opened 3 years ago

michaelpj commented 3 years ago

readBigUInt and readBigNInt assume (https://github.com/well-typed/cborg/blob/master/cborg/src/Codec/CBOR/Read.hs#L2660) that the payload is a definite-length bytestring, although as far as I can see the specification merely says it his a "byte string data item", which I think means both definite and indefinite length bytestrings should be allowed.

Example (bigint tag, and then a random indefinite-length bytestring I got the library to make for me):

> let y :: Term = deserialise $ BSL.fromStrict (BS.pack [0xc2, 0x5f, 0x43, 0x6c, 0x6f, 0x6c, 0xff])
> y
*** Exception: DeserialiseFailure 0 "expected integer"