polydawn / refmt

Object mapping for golang.
MIT License
48 stars 14 forks source link

Fails to decode a valid CBOR object #43

Closed Stebalien closed 5 years ago

Stebalien commented 6 years ago

Specifically (base64 encoded):

pWNtYXgYGmNtaW4AZHByZXb3ZWJsb2Nr2CpYJQABcRIgnFmrwDoxE64kVL5FW13qCRd7b2Ik1wiT
53QXBnkSmNtlaW5kZXiic2VkZ2UuYXguc2YuVGVybWluYWyBa3RoZVRlcm1pbmFsdGVkZ2UuYXgu
c2YuVWlTZXNzaW9ugmg0RTgxNUU2M2lTb21lIEJvZHk=

This should decode to (python syntax):

{'max': 26, 'min': 0, 'prev': None, 'block': Tag(42, b'\x00\x01q\x12 \x9cY\xab\xc0:1\x13\xae$T\xbeE[]\xea\t\x17{ob$\xd7\x08\x93\xe7t\x17\x06y\x12\x98\xdb'), 'index': {'edge.ax.sf.Terminal': ['theTerminal'], 'edge.ax.sf.UiSession': ['4E815E63', 'Some Body']}}

Error:

Error: Invalid majorByte: 0xf7

Test case:

On go-ipfs 0.4.18, run: ipfs dag get zdpuArHM9moUGtzo47sHeQ5qS4jiuQApyMnFFLoBDdYeouwHy

Downstream bug https://github.com/ipfs/go-ipfs/issues/5776.

Stebalien commented 6 years ago

Looks like this is the undefined type. According to the spec, it looks like that should be used to indicate encoding errors... WHY? :sob:

It looks like we're not the first to trip over this: https://github.com/FasterXML/jackson-dataformats-binary/issues/93

I'm going to suggest the same solution: silently coerce to null (maybe we should make that optional)?

warpfork commented 5 years ago

cbor.DecodeOptions{CoerceUndefToNull:true} is now supported :tada: