-
Notifications
You must be signed in to change notification settings - Fork 60
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
Disable conflicting encode options when marshaling cbor.Tag. #546
Conversation
@fxamacker PTAL. I wanted to get a proposed solution up before the end of the week in order to avoid delaying the next release. I'm happy to resolve this in a different way if you prefer. |
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.
@benluddy Thanks for opening this PR and great discussion in the issue comments.
For unrecognized tag numbers, the library does not have enough information to detect tag validity errors. The application ultimately has to be responsible for validity errors in any special Tag values it directly creates and marshals.
I agree!
To address the immediate issue, I propose special-casing this in encodeTag (and maintaining similar special cases as necessary to make Tag marshaling "do the right thing" for the built-in tags).
I like this approach. It is effective without breaking changes.
In addition to current built-in tags, I wonder if we should special case more tags defined in RFC 8949 section 3.4 table 5, specifically CBOR tags 24, 32, 33, 34, and 36.
It is very likely that codec will have built-in support for more tags defined in RFC 8949. It would be safer to disable settings that might create tag validity issues for those tags.
Thoughts?
b2ef3f4
to
418369a
Compare
It's a good question. I'm wary by default about maintaining more special cases than necessary. The behavior of the default options hasn't changed, so at least existing programs that are processing those tags using Eventually (v3 wish list?), I think it would be great to arrive at a place like:
|
Encode options, especially those that control the mapping from Go type to CBOR type, can result in output containing tag validity errors. For tag numbers that are built in, it's possible to "do the right thing" and override those options on a case-by-case basis. This can't and does not prevent tag validity errors for unrecognized tag numbers. Signed-off-by: Ben Luddy <[email protected]>
418369a
to
0cabb4a
Compare
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.
Sounds good! Thanks for adding comments and updating tests.
Closes #545
Encode options, especially those that control the mapping from Go type to CBOR type, can result in output containing tag validity errors. For tag numbers that are built in, it's possible to "do the right thing" and override those options on a case-by-case basis. This can't and does not prevent tag validity errors for unrecognized tag numbers.
Description
PR Was Proposed and Welcomed in Currently Open Issue
ByteSliceMode
(unreleased new feature) can encode invalid CBOR data #545Checklist (for code PR only, ignore for docs PR)
Last line of each commit message should be in this format:
Signed-off-by: Firstname Lastname [email protected]
(see next section).
Certify the Developer's Certificate of Origin 1.1
the Developer Certificate of Origin 1.1.