From d20db279dccf419cd296c9ac4bfbfc4922d24df2 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Thu, 25 Mar 2021 03:19:40 -0400 Subject: [PATCH 1/2] Avoid a buffer copy when decoding utf-8 in node 10 --- lib/stdio_protocol.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stdio_protocol.ts b/lib/stdio_protocol.ts index 3e96a8679f2..d924e43df6e 100644 --- a/lib/stdio_protocol.ts +++ b/lib/stdio_protocol.ts @@ -352,7 +352,7 @@ else if (typeof Buffer !== 'undefined') { return buffer; }; - decodeUTF8 = bytes => Buffer.from(bytes).toString(); + decodeUTF8 = bytes => Buffer.from(bytes.buffer).toString(); } else { From ffe21706242ba6b2b10fee5c007674b42ec723d1 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Thu, 25 Mar 2021 03:58:43 -0400 Subject: [PATCH 2/2] Ensure we only decode the TypedArray's view --- lib/stdio_protocol.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/stdio_protocol.ts b/lib/stdio_protocol.ts index d924e43df6e..945513f7a6f 100644 --- a/lib/stdio_protocol.ts +++ b/lib/stdio_protocol.ts @@ -352,7 +352,10 @@ else if (typeof Buffer !== 'undefined') { return buffer; }; - decodeUTF8 = bytes => Buffer.from(bytes.buffer).toString(); + decodeUTF8 = bytes => { + let { buffer, byteOffset, byteLength } = bytes; + return Buffer.from(buffer, byteOffset, byteLength).toString(); + } } else {