-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid read in node::base64_decode<char>(char*, unsigned long, char const*, unsigned long) #2166
Comments
It's a universal problem independent of workers. Examine the code and you'll see that it was incorrect. |
@kzc do you have an example of code that shows this issue? |
|
@kzc a pull request to fix this would be gladly welcomed! :) |
@kzc Can this be reproduced with just JS code? I tried
it prints |
@thefourtheye did you |
Are you sure it's not just null terminating the string, that's what ur supposed to do in C? |
On the worker threads branch you can reproduce it with:
But again I want to stress that the issue is not unique to that branch. Apparently with a call to some crypto hash update method it is possible to create such a case - see the valgrind stack traces at the top of this ticket. Unfortunately I don't have the time to isolate the specific sequence of JS instructions that lead to the valgrind error. Even if reading an extra byte beyond the input byte range seems harmless in most cases, it does waste a few CPU cycles on computing an extra |
Despite my initial objection, @petkaantonov would you mind putting the |
sure |
Make the inner loop execute fewer compare-and-branch executions per processed byte, resulting in a 50% or more speedup. This coincidentally fixes an out-of-bounds read: while (unbase64(*src) < 0 && src < srcEnd) Should have read: while (src < srcEnd && unbase64(*src) < 0) But this commit removes the offending code altogether. Fixes: nodejs#2166 PR-URL: nodejs#2193 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Found this while
valgrind
ing the worker threads implementation:Likely fix:
The text was updated successfully, but these errors were encountered: