From f1fc708d816def60c5fc2fe7bb3e43d3d6f75ec6 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Thu, 1 Aug 2024 09:38:46 +0200 Subject: fix(ext/crypto): respect offsets when writing into ab views in randomFillSync (#24816) --- ext/node/polyfills/internal/crypto/_randomFill.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ext/node') diff --git a/ext/node/polyfills/internal/crypto/_randomFill.mjs b/ext/node/polyfills/internal/crypto/_randomFill.mjs index 5de756536..e53918b39 100644 --- a/ext/node/polyfills/internal/crypto/_randomFill.mjs +++ b/ext/node/polyfills/internal/crypto/_randomFill.mjs @@ -86,7 +86,9 @@ export function randomFillSync(buf, offset = 0, size) { return buf; } - const bytes = new Uint8Array(buf.buffer ? buf.buffer : buf, offset, size); + const bytes = isAnyArrayBuffer(buf) + ? new Uint8Array(buf, offset, size) + : new Uint8Array(buf.buffer, buf.byteOffset + offset, size); op_node_generate_secret(bytes); return buf; -- cgit v1.2.3