-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
CBOR.decode can raise several error types when fed with invalid cbor input.
require "cbor"
require 'securerandom'
errors = {}
1_000_000.times do |i|
begin
CBOR.decode(SecureRandom.random_bytes(64))
rescue => ex
errors[ex.class.name] = ex
end
end
pp errorsreturns
{"CBOR::MalformedFormatError"=>
#<CBOR::MalformedFormatError: extra bytes follow after a deserialized object>,
"EOFError"=>#<EOFError: end of buffer reached>,
"TypeError"=>#<TypeError: can't convert CBOR::Simple into an exact number>,
"URI::InvalidURIError"=>#<URI::InvalidURIError: bad URI(is not URI?): 2>,
"FloatDomainError"=>#<FloatDomainError: NaN>,
"RegexpError"=>
#<RegexpError: invalid multibyte character: /\x1Er\x13w\xBCx0N:n\xD3aw{\x98\xB1Q\x1D\xC0\u06FC5\xF0/>}
Do you think it's possible for the CBOR decoder to either provide some sort fo CBOR.valid?(input) method, or for CBOR.decode(input) to always return the same exception when input is detected to be invalid CBOR?
This was raised in cedarcode/cose-ruby#40.
Thank you in advance!
lgarron
Metadata
Metadata
Assignees
Labels
No labels