cbor / cbor.github.io

cbor.io web site
75 stars 33 forks source link

cbor.me decoder internal error on bignum inputs #22

Closed PJK closed 7 years ago

PJK commented 7 years ago

The following sequence is not correctly handled:

a2 9b 80 00 00 00 00 00 00 00 00 00 00 00 00 00

(Also see PJK/libcbor#16)

cabo commented 7 years ago

Oh, Array.new(2**63) throws an exception in Ruby (the wrong one, by the way). That's the internal server error you should be seeing; I need to catch that exception. What did you expect to get?

PJK commented 7 years ago

What did you expect to get?

I'd say an error explaining what went wrong, to make it consistent with error handling for other invalid inputs. For example, if I try converting xx, I get Out of bytes to decode: 1.

Note that in principle this CBOR fragment is not invalid because of the size being unrealistically high, but because it is not followed by the expected number of bytes. Thus if you decide to show something along the lines of bignum too big to convert intolong' (RangeError)` (I understand that the webapp is based on the gem?), it should clearly say that this indicates a limitation of the implementation, not the actual problem with the input.

cabo commented 7 years ago

Indeed, I shouldn't even try to allocate the array of size x unless there are at least x bytes of input left. Will be in 0.2.4.

cabo commented 7 years ago

Fixed in https://github.com/cabo/cbor-diag/commit/3d322ccb50bd6fb73013bd162d76000c90be9508 -- now running on http://cbor.me