From 2007eb5c962079c9cc958bc02cf40df2dc218751 Mon Sep 17 00:00:00 2001 From: cola119 Date: Mon, 31 Oct 2022 22:27:03 +0900 Subject: [PATCH] fixup! lib: fix TypeError when converting a detached buffer source --- lib/internal/encoding.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index 0dec915124bf30..3a3d558361e118 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -491,10 +491,18 @@ function makeTextDecoderJS() { decode(input = empty, options = kEmptyObject) { validateDecoder(this); if (isAnyArrayBuffer(input)) { - input = lazyBuffer().from(input); + try { + input = lazyBuffer().from(input); + } catch { + input = empty; + } } else if (isArrayBufferView(input)) { - input = lazyBuffer().from(input.buffer, input.byteOffset, - input.byteLength); + try { + input = lazyBuffer().from(input.buffer, input.byteOffset, + input.byteLength); + } catch { + input = empty; + } } else { throw new ERR_INVALID_ARG_TYPE('input', ['ArrayBuffer', 'ArrayBufferView'],