From ff4226a3cd20ef6cfb155ca206c745785b6e098f Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Fri, 16 Aug 2024 09:48:57 -0700 Subject: fix(node/fs): Use correct offset and length in node:fs.read and write (#25049) My fix in #25030 was buggy, I forgot to pass the `byteOffset` and `byteLength`. Whoops. I also discovered that fs.read was not respecting the `offset` argument, and we were constructing a new `Buffer` for the callback instead of just passing the original one (which is what node does, and the @types/node definitions also indicate the callback should get the same type). Fixes #25028. --- ext/node/polyfills/internal/fs/utils.mjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ext/node/polyfills/internal/fs/utils.mjs') diff --git a/ext/node/polyfills/internal/fs/utils.mjs b/ext/node/polyfills/internal/fs/utils.mjs index 53184b9c3..b0ef34873 100644 --- a/ext/node/polyfills/internal/fs/utils.mjs +++ b/ext/node/polyfills/internal/fs/utils.mjs @@ -990,7 +990,11 @@ export const validatePosition = hideStackFrames((position) => { export const arrayBufferViewToUint8Array = hideStackFrames( (buffer) => { if (!(buffer instanceof Uint8Array)) { - return new Uint8Array(buffer.buffer); + return new Uint8Array( + buffer.buffer, + buffer.byteOffset, + buffer.byteLength, + ); } return buffer; }, -- cgit v1.2.3