Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Crash when trying to create buffers with invalid base64. #3496
Comments
mscdex
added
the
buffer
label
Oct 23, 2015
|
/cc @trevnorris |
|
I can reproduce this. |
btipling
commented
Oct 23, 2015
|
I can confirm that this also crashes on Amazon Linux AMI:
It did not crash on OS X for me. |
ggreer
commented
Oct 23, 2015
|
Just FYI, this also crashes on FreeBSD 10.1-RELEASE:
That's using node.js v4.2.1 from ports. |
brendanashworth
added
the
confirmed-bug
label
Oct 23, 2015
bnoordhuis
referenced this issue
Oct 23, 2015
Merged
buffer: don't CHECK on zero-sized realloc #3499
|
@bnoordhuis - your PR seem to solve the crash which happens when failing to parse a string with output > 4096 (base64 input > 5641). |
ggreer
commented
Oct 23, 2015
|
It'd be nice to throw an exception if invalid base64 was passed into Right now though, I just want node to not crash. |
bnoordhuis
added a commit
to bnoordhuis/io.js
that referenced
this issue
Oct 23, 2015
|
|
bnoordhuis |
594500f
|
bnoordhuis
closed this
in #3499
Oct 23, 2015
@jhamhader The base64 decoder's behavior is backwards compatible (going back all the way to v0.1.x, IIRC.) It's allowed to pass in base64 data with trailing gunk and (some) interior gunk. To wit, one of my first contributions to node was a better base64 decoder. One of my first bug fixes was for the regression it introduced because it was too strict. :-) If you want to ensure that all input has been decoded, you would have to validate it yourself. Assuming valid base64 without whitespace, the decoded size should be |
bnoordhuis
added a commit
that referenced
this issue
Oct 26, 2015
|
|
bnoordhuis + jasnell |
287e830
|
bnoordhuis
added a commit
that referenced
this issue
Oct 26, 2015
|
|
bnoordhuis + rvagg |
1a41feb
|
bnoordhuis
added a commit
that referenced
this issue
Oct 29, 2015
|
|
bnoordhuis + jasnell |
2a45b72
|
ggreer commentedOct 23, 2015
I've been having this problem intermittently in production, and (with the help of @kans) managed to create a reproducible test case. This is on Ubuntu 15.04 using node.js v4.2.1 (built from source):
In the Buffer constructor (https://github.com/nodejs/node/blob/master/src/node_buffer.cc#L224), it looks like
StringBytes::Write()fails and returns zero. Thenrealloc()is called with a length of zero. On linux, this frees the memory and returns a null pointer. Then the null assertion fails and node crashes.realloc()behaves differently on OS X, so this won't crash on a mac.