summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorGeert-Jan Zwiers <geertjanzwiers@protonmail.com>2022-09-01 22:20:11 +0200
committerGitHub <noreply@github.com>2022-09-01 22:20:11 +0200
commit58e76098e6325ad16d552924d58c33bad6573c07 (patch)
treefe4016ce33c45fb3649504e072677f2dba9e2fcd /cli
parent778eb1da24ac77635ffbc24e05e826bca973199b (diff)
fix(serde_v8): no panic on reading large text file (#15494)
Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
Diffstat (limited to 'cli')
-rw-r--r--cli/tests/unit/read_text_file_test.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/cli/tests/unit/read_text_file_test.ts b/cli/tests/unit/read_text_file_test.ts
index 169972cb4..48d246dad 100644
--- a/cli/tests/unit/read_text_file_test.ts
+++ b/cli/tests/unit/read_text_file_test.ts
@@ -145,3 +145,45 @@ Deno.test(
assert(data.length > 0);
},
);
+
+Deno.test(
+ { permissions: { read: true, write: true } },
+ function readTextFileSyncV8LimitError() {
+ const kStringMaxLengthPlusOne = 536870888 + 1;
+ const bytes = new Uint8Array(kStringMaxLengthPlusOne);
+ const filePath = "cli/tests/testdata/too_big_a_file.txt";
+
+ Deno.writeFileSync(filePath, bytes);
+
+ assertThrows(
+ () => {
+ Deno.readTextFileSync(filePath);
+ },
+ TypeError,
+ "buffer exceeds maximum length",
+ );
+
+ Deno.removeSync(filePath);
+ },
+);
+
+Deno.test(
+ { permissions: { read: true, write: true } },
+ async function readTextFileV8LimitError() {
+ const kStringMaxLengthPlusOne = 536870888 + 1;
+ const bytes = new Uint8Array(kStringMaxLengthPlusOne);
+ const filePath = "cli/tests/testdata/too_big_a_file_2.txt";
+
+ await Deno.writeFile(filePath, bytes);
+
+ await assertRejects(
+ async () => {
+ await Deno.readTextFile(filePath);
+ },
+ TypeError,
+ "buffer exceeds maximum length",
+ );
+
+ await Deno.remove(filePath);
+ },
+);