From ab9c7f52e0a729de9d8c535cfd77e72cc1ca8512 Mon Sep 17 00:00:00 2001 From: Geert-Jan Zwiers Date: Thu, 26 May 2022 17:15:44 +0200 Subject: chore(serde_v8): throw error when string buffer exceeds v8 max length (#14588) --- cli/tests/unit/buffer_test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'cli/tests/unit/buffer_test.ts') diff --git a/cli/tests/unit/buffer_test.ts b/cli/tests/unit/buffer_test.ts index 445c946e2..41d7e4d7f 100644 --- a/cli/tests/unit/buffer_test.ts +++ b/cli/tests/unit/buffer_test.ts @@ -446,3 +446,16 @@ Deno.test(function testBufferBytesCopyFalseGrowExactBytes() { assertEquals(actualBytes.byteLength, bufSize); assertEquals(actualBytes.buffer.byteLength, actualBytes.byteLength); }); + +Deno.test(function testThrowsErrorWhenBufferExceedsMaxLength() { + const kStringMaxLengthPlusOne = 536870888 + 1; + const bytes = new Uint8Array(kStringMaxLengthPlusOne); + + assertThrows( + () => { + new TextDecoder().decode(bytes); + }, + TypeError, + "buffer exceeds maximum length", + ); +}); -- cgit v1.2.3