diff --git a/src/lib/waku_message/version_1.ts b/src/lib/waku_message/version_1.ts index 5a77c7f930..a43378e826 100644 --- a/src/lib/waku_message/version_1.ts +++ b/src/lib/waku_message/version_1.ts @@ -94,7 +94,7 @@ export function clearDecode( const sizeOfPayloadSizeField = getSizeOfPayloadSizeField(message); if (sizeOfPayloadSizeField === 0) return; - const payloadSize = buf.readUIntLE(start, sizeOfPayloadSizeField); + const payloadSize = getPayloadSize(message, sizeOfPayloadSizeField); start += sizeOfPayloadSizeField; const payload = buf.slice(start, start + payloadSize); @@ -114,6 +114,14 @@ function getSizeOfPayloadSizeField(message: Uint8Array): number { return messageDataView.getUint8(0) & FlagMask; } +function getPayloadSize( + message: Uint8Array, + sizeOfPayloadSizeField: number +): number { + const buf = Buffer.from(message); + return buf.readUIntLE(1, sizeOfPayloadSizeField); +} + /** * Proceed with Asymmetric encryption of the data as per [26/WAKU-PAYLOAD](https://rfc.vac.dev/spec/26/). * The data MUST be flags | payload-length | payload | [signature].