Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eb393f9

Browse filesBrowse files
seishunMylesBorins
authored andcommitted
src: fix base64 decoding
Make sure trailing garbage is not treated as a valid base64 character. Fixes: #11987 PR-URL: #11995 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 7a1920d commit eb393f9
Copy full SHA for eb393f9

File tree

Expand file treeCollapse file tree

2 files changed

+6
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+6
-2
lines changed
Open diff view settings
Collapse file

‎src/string_bytes.cc‎

Copy file name to clipboardExpand all lines: src/string_bytes.cc
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ size_t base64_decode_slow(char* dst, size_t dstlen,
174174
size_t k = 0;
175175
for (;;) {
176176
#define V(expr) \
177-
while (i < srclen) { \
177+
for (;;) { \
178178
const uint8_t c = src[i]; \
179179
lo = unbase64(c); \
180180
i += 1; \
181181
if (lo < 64) \
182182
break; /* Legal character. */ \
183-
if (c == '=') \
183+
if (c == '=' || i >= srclen) \
184184
return k; \
185185
} \
186186
expr; \
Collapse file

‎test/parallel/test-buffer-alloc.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-alloc.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,10 @@ assert.equal(dot.toString('base64'), '//4uAA==');
696696
// Regression test for https://github.com/nodejs/node/issues/3496.
697697
assert.equal(Buffer.from('=bad'.repeat(1e4), 'base64').length, 0);
698698

699+
// Regression test for https://github.com/nodejs/node/issues/11987.
700+
assert.deepStrictEqual(Buffer.from('w0 ', 'base64'),
701+
Buffer.from('w0', 'base64'));
702+
699703
{
700704
// Creating buffers larger than pool size.
701705
const l = Buffer.poolSize + 5;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.