From 2fdbb5e806a803591c6f157a42440ce068e652c0 Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Fri, 6 Mar 2020 06:30:07 -0500 Subject: [PATCH 1/2] test: `buffer.write` with longer string scenario Make sure longer strings are written up to the buffer end Refs: https://github.com/nodejs/node/pull/32119 --- test/parallel/test-buffer-write.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/parallel/test-buffer-write.js b/test/parallel/test-buffer-write.js index 1f080add08451f..2038bc46b74ed9 100644 --- a/test/parallel/test-buffer-write.js +++ b/test/parallel/test-buffer-write.js @@ -90,6 +90,8 @@ for (let i = 1; i < 4; i++) { const z = Buffer.alloc(4, 0); assert.strictEqual(z.write('\u0001', 3, 'ucs2'), 0); assert.strictEqual(Buffer.compare(z, Buffer.alloc(4, 0)), 0); +// Make sure longer strings are written up to the buffer end. +assert.strictEqual(z.write('abcd', 2), 2); // Large overrun could corrupt the process assert.strictEqual(Buffer.alloc(4) From 877f0626ffeb9b970be0b2e3baa0aa1724aa4947 Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Mon, 9 Mar 2020 01:23:10 -0400 Subject: [PATCH 2/2] fixup: address review comment --- test/parallel/test-buffer-write.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-buffer-write.js b/test/parallel/test-buffer-write.js index 2038bc46b74ed9..842b12c04c04db 100644 --- a/test/parallel/test-buffer-write.js +++ b/test/parallel/test-buffer-write.js @@ -92,6 +92,7 @@ assert.strictEqual(z.write('\u0001', 3, 'ucs2'), 0); assert.strictEqual(Buffer.compare(z, Buffer.alloc(4, 0)), 0); // Make sure longer strings are written up to the buffer end. assert.strictEqual(z.write('abcd', 2), 2); +assert.deepStrictEqual([...z], [0, 0, 0x61, 0x62]); // Large overrun could corrupt the process assert.strictEqual(Buffer.alloc(4)