Repository navigation
fix(cbor): stop decoding at the end of the input and bound declared lengths - #663
solidsnakedev wants to merge 3 commits into
Conversation
…engths decodeItemAt throws CBORError at an offset past the end of the input, and decodeArrayAt and decodeMapAt reject a definite length larger than the bytes left before they loop or allocate.
|
One extra case from verifying this against the same inputs, in case it helps: the 4-byte length in
Reading that length unsigned ( Building in the open as an independent Cardano developer — not affiliated with the Cardano Foundation, IOG or Intersect. @Kshot9000 · https://x.com/kshot9000 · github.com/Kshot3000 |
CBOR.fromCBORHex("9a7fffffff")aborted the Node process with an out-of-memory error, andTransaction.fromCBORHexdid the same. The five bytes declare an array of 2^31 - 1 items. Past the end of the input,decodeItemAtreadundefinedas an integer and returned an item. SodecodeArrayAtlooped over the declared length and filled the array it had allocated for it, and the map formba7fffffffran for tens of seconds.decodeItemAtnow throwsCBORErrorat the end of the input.decodeArrayAtanddecodeMapAtreject a definite length larger than the bytes left before they loop or allocate. Every array item takes at least one byte and every map entry two. Well-formed CBOR never meets either check, and decoding an 859 KB value takes the same time as before.Closes #661