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
encoding/asn1: document that Unmarshal drops trailing elements #38545
Comments
For better or for worse, that is how the encoding/asn1 package works. There is a comment in the source code: // We allow extra bytes at the end of the SEQUENCE because
// adding elements to the end has been used in X.509 as the
// version numbers have increased. I don't think we can change that now. CC @agl @FiloSottile |
That's fine, I guess people would have to live with that, however:
|
Yes, we can certainly change the documentation. Want to send a patch? |
I think it's best if someone else does it. I have no knowledge of ASN1 and I also opened this throwaway user just for reporting this. |
This is indeed intended behavior, although something that surprised me at some point, too. Adding elements to SEQUENCEs is how ASN.1 is extended. If you want to check there's no extra elements, you should use golang.org/x/crypto/cryptobyte instead (and we do here and there for things like signature parsing). |
rest is needed? initOffset is always zero and json.Unmarshal returns only error.
|
Change https://golang.org/cl/233537 mentions this issue: |
Marking this as a duplicate of #35680, which is addressed in https://golang.org/cl/233537. |
What version of Go are you using (
go version
)?go1.14
Does this issue reproduce with the latest release?
Yes, on Go playground the current version is 1.14.2
What did you do?
As shown in the following Go playground snippet, I define 2 structs:
and then I first feed the smaller struct (AB) instance into the larger one (ABC):
then I assign the third field of the larger instance (ABC) and marshal the larger instance (ABC) to bytes
Followed by pouring the bytes from the larger instance (ABC) into an empty smaller instance (AB):
What did you expect to see?
I expected the rest not to be empty! I should get a hint that there were trailing bytes, should I not?
What did you see instead?
The rest is empty and no error was returned.
Needless to say, some applications might be... sensitive to this kind of behavior.
The text was updated successfully, but these errors were encountered: