src: fix decoding base64 with whitespace
`max_i` should also include the characters that were just read by `base64_decode_group_slow()`. PR-URL: https://github.com/nodejs/node/pull/13660 Fixes: https://github.com/nodejs/node/issues/13636 Fixes: https://github.com/nodejs/node/issues/13657 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
00aac57df9
commit
64812f5728
@ -99,10 +99,9 @@ size_t base64_decode_fast(char* const dst, const size_t dstlen,
|
|||||||
unbase64(src[i + 3]);
|
unbase64(src[i + 3]);
|
||||||
// If MSB is set, input contains whitespace or is not valid base64.
|
// If MSB is set, input contains whitespace or is not valid base64.
|
||||||
if (v & 0x80808080) {
|
if (v & 0x80808080) {
|
||||||
const size_t old_i = i;
|
|
||||||
if (!base64_decode_group_slow(dst, dstlen, src, srclen, &i, &k))
|
if (!base64_decode_group_slow(dst, dstlen, src, srclen, &i, &k))
|
||||||
return 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 {
|
} else {
|
||||||
dst[k + 0] = ((v >> 22) & 0xFC) | ((v >> 20) & 0x03);
|
dst[k + 0] = ((v >> 22) & 0xFC) | ((v >> 20) & 0x03);
|
||||||
dst[k + 1] = ((v >> 12) & 0xF0) | ((v >> 10) & 0x0F);
|
dst[k + 1] = ((v >> 12) & 0xF0) | ((v >> 10) & 0x0F);
|
||||||
|
@ -468,6 +468,10 @@ assert.strictEqual(Buffer.from('=bad'.repeat(1e4), 'base64').length, 0);
|
|||||||
assert.deepStrictEqual(Buffer.from('w0 ', 'base64'),
|
assert.deepStrictEqual(Buffer.from('w0 ', 'base64'),
|
||||||
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.
|
// Creating buffers larger than pool size.
|
||||||
const l = Buffer.poolSize + 5;
|
const l = Buffer.poolSize + 5;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user