The base32 library we're using (https://www.npmjs.com/package/base32-encode) takes an ArrayBuffer as input instead of a view like Uint8Array. This can be problematic if the Uint8Array generated as cborldBytes is a view on an ArrayBuffer that has a different length than the Uint8Array. For example, imagine an ArrayBuffer that is 8 KiB and the Uint8Array is only 100 bytes somewhere in the middle of that buffer.
To address this, we should add code to compare the length of the Uint8Array to its underlying buffer before passing the underlying buffer to the encode function. If the lengths are different, we need to create a new ArrayBuffer with a matching length and copy the data from the Uint8Array into it.
Alternatively, we should talk with the author of the lib and see what should be done about this potential problem; perhaps their intent was to just allow any TypedArray to be passed in -- and we could get their docs updated or something. The code, as-is, would accept a Uint8Array directly without issue.
The base32 library we're using (https://www.npmjs.com/package/base32-encode) takes an
ArrayBuffer
as input instead of a view likeUint8Array
. This can be problematic if theUint8Array
generated ascborldBytes
is a view on anArrayBuffer
that has a different length than theUint8Array
. For example, imagine anArrayBuffer
that is 8 KiB and theUint8Array
is only 100 bytes somewhere in the middle of that buffer.To address this, we should add code to compare the length of the
Uint8Array
to its underlying buffer before passing the underlying buffer to the encode function. If the lengths are different, we need to create a newArrayBuffer
with a matching length and copy the data from theUint8Array
into it.Alternatively, we should talk with the author of the lib and see what should be done about this potential problem; perhaps their intent was to just allow any
TypedArray
to be passed in -- and we could get their docs updated or something. The code, as-is, would accept aUint8Array
directly without issue.