diff --git a/src/string_bytes.cc b/src/string_bytes.cc index a650ac0b00452e..8cb669e223eeba 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -174,13 +174,13 @@ size_t base64_decode_slow(char* dst, size_t dstlen, size_t k = 0; for (;;) { #define V(expr) \ - while (i < srclen) { \ + for (;;) { \ const uint8_t c = src[i]; \ lo = unbase64(c); \ i += 1; \ if (lo < 64) \ break; /* Legal character. */ \ - if (c == '=') \ + if (c == '=' || i >= srclen) \ return k; \ } \ expr; \ diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index d3564ab81b8d92..49d628bfec58b0 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -696,6 +696,10 @@ assert.equal(dot.toString('base64'), '//4uAA=='); // Regression test for https://github.com/nodejs/node/issues/3496. assert.equal(Buffer.from('=bad'.repeat(1e4), 'base64').length, 0); +// Regression test for https://github.com/nodejs/node/issues/11987. +assert.deepStrictEqual(Buffer.from('w0 ', 'base64'), + Buffer.from('w0', 'base64')); + { // Creating buffers larger than pool size. const l = Buffer.poolSize + 5;