-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
buffer: remove unreachable overflow check in atob #60161
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
base: main
Are you sure you want to change the base?
Conversation
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #60161 +/- ##
==========================================
+ Coverage 88.53% 88.57% +0.03%
==========================================
Files 703 704 +1
Lines 207997 208125 +128
Branches 40015 40012 -3
==========================================
+ Hits 184150 184338 +188
+ Misses 15864 15815 -49
+ Partials 7983 7972 -11
🚀 New features to boost your workflow:
|
case -3: // Possible overflow | ||
// TODO(@anonrig): Throw correct error in here. | ||
throw lazyDOMException('The input causes overflow.', 'InvalidCharacterError'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An unrecognised error state shouldn't be ignored.
I was thinking something like
case -3:
assert.fail('Unrecognized simdutf error');
with internal assert added to the imports in the script header:
@@ -97,10 +97,11 @@ const {
} = require('internal/util/types');
const {
inspect: utilInspect,
} = require('internal/util/inspect');
+const assert = require('internal/assert');
const {
codes: {
ERR_BUFFER_OUT_OF_BOUNDS,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
This commit resolves a TODO comment in lib/buffer.js by changing the error thrown by atob() during a potential overflow condition.
Modified lib/buffer.js to instantiate and throw new ERR_INVALID_ARG_VALUE('input', result, 'The string to be decoded is too long.'); for the overflow case (result === -3).
This change makes the atob implementation more robust and developer-friendly.
@anonrig
->
The case for a result of -3 was intended to handle a potential
buffer overflow error. However, the underlying C++ implementation using
simdutf::base64_to_binary does not perform bounds-checking and therefore
can never return an OUTPUT_BUFFER_TOO_SMALL error.
This makes the
case -3:
block unreachable code. This commit removesthe dead code for correctness and clarity.