From 3f8ac4a81252e6aa03f4b15ce3d69b04b36e369f Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 16 Apr 2019 06:42:13 -0700 Subject: [PATCH 1/4] benchmark: fix buffer-base64-decode.js 693401d0ddd752e5fa47b882e56e252c42c94c0e added stricter range checking for buffer operations and that apparently seems to have uncovered the fact that one of our benchmarks was overflowing a buffer. Increase the buffer size so the benchmark doesn't throw an error anymore. --- benchmark/buffers/buffer-base64-decode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/buffers/buffer-base64-decode.js b/benchmark/buffers/buffer-base64-decode.js index 0ac694fe8c4ae7..27d53ce394c191 100644 --- a/benchmark/buffers/buffer-base64-decode.js +++ b/benchmark/buffers/buffer-base64-decode.js @@ -12,7 +12,7 @@ function main({ n, size }) { // eslint-disable-next-line node-core/no-unescaped-regexp-dot s.match(/./); // Flatten string. assert.strictEqual(s.length % 4, 0); - const b = Buffer.allocUnsafe(s.length / 4 * 3); + const b = Buffer.allocUnsafe(s.length); b.write(s, 0, s.length, 'base64'); bench.start(); for (var i = 0; i < n; i += 1) b.base64Write(s, 0, s.length); From eab7d506006be372b9855bb75a5fc27a0c6354af Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 16 Apr 2019 08:26:39 -0700 Subject: [PATCH 2/4] test: fix test-benchmark-buffer Using `len=2` in test-benchmark-buffer was resulting in a `RangeError` in buffer-base64-encode.js. Change to `len=256` which works in all buffer benchmarks. --- test/benchmark/test-benchmark-buffer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/benchmark/test-benchmark-buffer.js b/test/benchmark/test-benchmark-buffer.js index 171f755647d21f..d3085796e1a651 100644 --- a/test/benchmark/test-benchmark-buffer.js +++ b/test/benchmark/test-benchmark-buffer.js @@ -13,7 +13,7 @@ runBenchmark('buffers', 'charsPerLine=6', 'encoding=utf8', 'endian=BE', - 'len=2', + 'len=256', 'linesCount=1', 'method=', 'n=1', From b72b012f7cb1203b4504f385cefd9c808daaffd1 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 16 Apr 2019 11:30:56 -0700 Subject: [PATCH 3/4] fixup! benchmark: fix buffer-base64-decode.js --- benchmark/buffers/buffer-base64-decode.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmark/buffers/buffer-base64-decode.js b/benchmark/buffers/buffer-base64-decode.js index 27d53ce394c191..ed5d374c9b21b4 100644 --- a/benchmark/buffers/buffer-base64-decode.js +++ b/benchmark/buffers/buffer-base64-decode.js @@ -12,8 +12,8 @@ function main({ n, size }) { // eslint-disable-next-line node-core/no-unescaped-regexp-dot s.match(/./); // Flatten string. assert.strictEqual(s.length % 4, 0); - const b = Buffer.allocUnsafe(s.length); - b.write(s, 0, s.length, 'base64'); + const b = Buffer.allocUnsafe(size * 3); + b.write(s, 0, size * 3, 'base64'); bench.start(); for (var i = 0; i < n; i += 1) b.base64Write(s, 0, s.length); bench.end(n); From d371b3462f780e6f58f07414f790c84a8e1012d3 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 16 Apr 2019 13:04:41 -0700 Subject: [PATCH 4/4] fixup! fixup! benchmark: fix buffer-base64-decode.js --- benchmark/buffers/buffer-base64-decode.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/benchmark/buffers/buffer-base64-decode.js b/benchmark/buffers/buffer-base64-decode.js index ed5d374c9b21b4..d05b9ab3787fce 100644 --- a/benchmark/buffers/buffer-base64-decode.js +++ b/benchmark/buffers/buffer-base64-decode.js @@ -9,11 +9,12 @@ const bench = common.createBenchmark(main, { function main({ n, size }) { const s = 'abcd'.repeat(size); + const encodedSize = s.length * 3 / 4; // eslint-disable-next-line node-core/no-unescaped-regexp-dot s.match(/./); // Flatten string. assert.strictEqual(s.length % 4, 0); - const b = Buffer.allocUnsafe(size * 3); - b.write(s, 0, size * 3, 'base64'); + const b = Buffer.allocUnsafe(encodedSize); + b.write(s, 0, encodedSize, 'base64'); bench.start(); for (var i = 0; i < n; i += 1) b.base64Write(s, 0, s.length); bench.end(n);