-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Description
Hi. Nice library!
Encodings on Uint8Array subarrays yield incorrect results:
> encode(new Uint8Array([0x00, 0x86, 0x4F, 0xD2, 0x6F, 0xB5, 0x59, 0xF7, 0x5B]).slice(1)) // ✅
< 'HelloWorld'
> encode(new Uint8Array([0x00, 0x86, 0x4F, 0xD2, 0x6F, 0xB5, 0x59, 0xF7, 0x5B]).subarray(1)) // ❌
< '0esp$z)-:x'
I think if you pass the ui8a.byteOffset and ui8a.byteLength through to the DataView dw it will work for both use cases.
This can happen when z85 encoding multiple results from cbor-x encoding, which returns subarrays into a larger underlying encoding buffer:
> CBOR.encode('Hello')
< Uint8Array(6) [101, 72, 101, 108, 108, 111, buffer: ArrayBuffer(8192), byteLength: 6, byteOffset: 4674,
> CBOR.encode('World')
< Uint8Array(6) [101, 87, 111, 114, 108, 100, buffer: ArrayBuffer(8192), byteLength: 6, byteOffset: 4680,
I won't share how long it took me to figure out exactly what was going on here… 😳🙊
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels