From 119120d21ccc3d2424a607f0637b89a5aae871ec Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 10 Feb 2023 06:26:23 +0200 Subject: [simdutf] workaround validation OOB access (#2031) --- test/bun.js/buffer.test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'test/bun.js/buffer.test.js') diff --git a/test/bun.js/buffer.test.js b/test/bun.js/buffer.test.js index dba55ffe8..37484328b 100644 --- a/test/bun.js/buffer.test.js +++ b/test/bun.js/buffer.test.js @@ -2518,9 +2518,17 @@ test("Buffer.byteLength", () => { }); it("should not crash on invalid UTF-8 byte sequence", () => { - const buf = Buffer.from([0xc0, 0xfd]).toString(); + const buf = Buffer.from([0xc0, 0xfd]); expect(buf.length).toBe(2); const str = buf.toString(); expect(str.length).toBe(2); expect(str).toBe("\uFFFD\uFFFD"); }); + +it("should not perform out-of-bound access on invalid UTF-8 byte sequence", () => { + const buf = Buffer.from([0x01, 0x9a, 0x84, 0x13, 0x12, 0x11, 0x10, 0x09]).subarray(2); + expect(buf.length).toBe(6); + const str = buf.toString(); + expect(str.length).toBe(6); + expect(str).toBe("\uFFFD\x13\x12\x11\x10\x09"); +}); -- cgit v1.2.3