-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check well-formedness of data from MarshalCBOR #485
Check well-formedness of data from MarshalCBOR #485
Conversation
MarshalerError is returned if CBOR data item returned from MarshalCBOR() fails either: - well-formedness check, or - tag validation for builtin tags 0-3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank for for fixing this!
On a related subject, I'm curious if you have already had discussions about alternative ways for applications to customize marshaling behavior. I'm sure you're already aware of the limitations of the TextMarshaler/BinaryMarshaler-style interface design:
- additional heap allocations to support the []byte return value
- additional copy from the []byte return value to the encoder output
- inability to customize marshaling behavior for types that are external to an application (i.e. library types and built-in types)
- the encode options used by the caller aren't visible to the Marshaler on each invocation
- the Marshaler's output needs to be validated
Is that something you'd be interested in exploring (in a separate issue) in the future?
Yes, definitely! 👍 The current API is meant to be easy for users familiar with A more efficient and extensible API would definitely be useful as an alternative to |
This commit checks Marshaler data for well-formedness (and very limited partial validation) by reusing one of four DecModes created during startup. These modes are safe for parallel use by different Marshalers.
Closes #482
MarshalerError
is returned if CBOR data item returned fromMarshalCBOR()
fails either:Many thanks to @benluddy for reporting this bug! 👍