Skip to content

fix: error on decoding unordered keys#58

Open
vmx wants to merge 1 commit into
minimal-intsfrom
decode-unordered-error
Open

fix: error on decoding unordered keys#58
vmx wants to merge 1 commit into
minimal-intsfrom
decode-unordered-error

Conversation

@vmx
Copy link
Copy Markdown
Member

@vmx vmx commented Jun 2, 2026

DAG-CBOR requires map keys to be sorted. The decoder now errors if that's not the case.

A test case that existed before this became a DAG-CBOR library was removed, as it contains keys in the wrong order.

DAG-CBOR requires map keys to be sorted. The decoder now errors
if that's not the case.

A test case that existed before this became a DAG-CBOR library was
removed, as it contains keys in the wrong order.
@vmx vmx requested a review from rvagg June 2, 2026 10:07
@rvagg
Copy link
Copy Markdown
Member

rvagg commented Jun 3, 2026

Oh, are you sure you want to do this on decode? I've stopped short of doing this anywhere, decided that this wasn't a good reason to reject decode, just a good thing to do on encode. There exists in the wild a lot of data with unordered keys. Most notably is the Filecoin pre-genesis block which is ancient dag-cbor, but also all of those schema-driven dag-cbor blocks that obey a struct key order rather than ordering them. cbor-gen for instance I think never got any map sorting in it, thankfully it doesn't get used much for maps since we just do arrays for chain data, but there are maps around that it's generated.

@vmx
Copy link
Copy Markdown
Member Author

vmx commented Jun 3, 2026

My thought was, why not being as strict as possible, so that if anyone creates their own generators, also get failures from other libraries reading the data. If anyone complains, I could always relax things. Though

Most notably is the Filecoin pre-genesis block which is ancient dag-cbor,

Is a good point, which is something that might actually be something that breaks.

@rvagg
Copy link
Copy Markdown
Member

rvagg commented Jun 4, 2026

How hard is opt-out with this tooling? In go-ipld-prime it's not too hard to make a custom decoder that you turn strict off on, it helps justify opting in to strictness if you can fairly easily opt out. Although one challenge is how deep these components end up being in the stacks they're used in. At the bottom of something like Kubo, getting a strictness error means that turning strictnesss off is a blunt instrument, so we do need to carefully weigh the default decisions. Key ordering is one that I don't think I want to pull the trigger on, I'd rather opt-in to that rather than forcing an opt out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants