Titan-C / cardano.el

GNU General Public License v3.0
20 stars 5 forks source link

Fix encoding of strings of length 256 (or 2^16 or 2^32) #1

Closed plexus closed 1 year ago

plexus commented 1 year ago

I hope this is the right place to submit a patch for the CBOR package found on MELPA.

There is currently an issue in cbor.el where strings with a length of exactly 256 are encoded as if they had a length of 0. This causes the UTF-8 bytes of the string to be interpreted as CBOR bytes, leading to a garbled message.

The greatest number that can be encoded in a single byte is 255, for a string of length 256 we need a second byte to encode the length.

Titan-C commented 1 year ago

Thank you for noticing this. It is actually a serious bug on all integer encoding. I added tests at each integer length type.

plexus commented 1 year ago

Thanks for the fix!