Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
encoding/asn1: Marshal/Unmarshal will create/parse invalid SETs #39036
Marshal and Unmarshal will happily encode and parse invalid SETs. Every component of a SET must have a distinct tag, either by using distinct types of each field or using explicit tagging to get around having multiple non-distinct fields. This specification of SETs allows for undefined ordering of components, since in theory each component can only map to a single field.
Currently Marshal ignores this and will happily encode a SET with multiple identical component tags. Similarly Unmarshal will parse an invalid SET. Due to how parsing works though (SETs are parsed in order, the same as SEQUENCEs, so unordered SETs with distinct fields cannot be parsed, see #19873) enforcing this constraint wouldn't provide significant benefit.
I took a stab at this in https://go-review.googlesource.com/c/go/+/233199, but realized that the naive approach of just using the field type was not sufficient. Really the struct test would need to take the final tag for a field into account, after explicit tagging etc has been applied, but unfortunately there is a bunch of logic that happens outside of