summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/base64.h3
-rw-r--r--test/parallel/test-buffer-alloc.js4
2 files changed, 5 insertions, 2 deletions
diff --git a/src/base64.h b/src/base64.h
index 2e0f8e3858..89c6251ef8 100644
--- a/src/base64.h
+++ b/src/base64.h
@@ -99,10 +99,9 @@ size_t base64_decode_fast(char* const dst, const size_t dstlen,
unbase64(src[i + 3]);
// If MSB is set, input contains whitespace or is not valid base64.
if (v & 0x80808080) {
- const size_t old_i = i;
if (!base64_decode_group_slow(dst, dstlen, src, srclen, &i, &k))
return k;
- max_i = old_i + (srclen - i) / 4 * 4; // Align max_i again.
+ max_i = i + (srclen - i) / 4 * 4; // Align max_i again.
} else {
dst[k + 0] = ((v >> 22) & 0xFC) | ((v >> 20) & 0x03);
dst[k + 1] = ((v >> 12) & 0xF0) | ((v >> 10) & 0x0F);
diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js
index a2095c31c0..df0d1c6d09 100644
--- a/test/parallel/test-buffer-alloc.js
+++ b/test/parallel/test-buffer-alloc.js
@@ -468,6 +468,10 @@ assert.strictEqual(Buffer.from('=bad'.repeat(1e4), 'base64').length, 0);
assert.deepStrictEqual(Buffer.from('w0 ', 'base64'),
Buffer.from('w0', 'base64'));
+// Regression test for https://github.com/nodejs/node/issues/13657.
+assert.deepStrictEqual(Buffer.from(' YWJvcnVtLg', 'base64'),
+ Buffer.from('YWJvcnVtLg', 'base64'));
+
{
// Creating buffers larger than pool size.
const l = Buffer.poolSize + 5;