Closed lgarron closed 5 years ago
After digging into this a bit more, looks like this is all in the CBOR decoding (e.g. https://github.com/cabo/cbor-ruby/issues/11).
This might be a hard problem to solve safely for the general case of CBOR decoding, but it would be nice if trying to decode limited-format public keys was more predictable and resource-constrained.
FWIW, based 100 million test runs, it seems the errors that COSE::Key.deserialize
can throw include at least:
CBOR::MalformedFormatError
TypeError
EOFError
COSE::UnknownKeyType
ArgumentError
NoMemoryError
URI::InvalidURIError
NoMethodError
IndexError
RegexpError
FloatDomainError
Hi @lgarron,
Thanks for reporting and identifying the issue in cbor
.
Can't reproduce any more after updating cbor
gem to 0.5.9.6
.
If you run
COSE::Key.deserialize(SecureRandom.random_bytes(64))
, then there is a fairly high chance of aNoMemoryError
. I think it would be nice if a compact untrusted input always throws a recoverable error.The following repro code crashes for me pretty reliably:
Sample output: