Skip to content

Commit dd4482e

Browse files
haramjaduh95
authored andcommitted
buffer: remove unreachable overflow check in atob
Signed-off-by: haramjeong <04harams77@gmail.com> PR-URL: #60161 Reviewed-By: René <contact.9a5d6388@renegade334.me.uk> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent a46bc45 commit dd4482e

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎lib/buffer.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ const {
112112
inspect: utilInspect,
113113
}=require('internal/util/inspect');
114114

115+
constassert=require('internal/assert');
116+
115117
const{
116118
codes: {
117119
ERR_BUFFER_OUT_OF_BOUNDS,
@@ -1389,9 +1391,9 @@ function atob(input) {
13891391
throwlazyDOMException(
13901392
'The string to be decoded is not correctly encoded.',
13911393
'InvalidCharacterError');
1392-
case-3:// Possible overflow
1393-
// TODO(@anonrig): Throw correct error in here.
1394-
throwlazyDOMException('The input causes overflow.','InvalidCharacterError');
1394+
case-3:
1395+
assert.fail('Unrecognized simdutf error');
1396+
break;
13951397
default:
13961398
returnresult;
13971399
}

‎src/node_buffer.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ static void Btoa(const FunctionCallbackInfo<Value>& args) {
14131413
// In case of error, a negative value is returned:
14141414
// * -1 indicates a single character remained,
14151415
// * -2 indicates an invalid character,
1416-
// * -3 indicates a possible overflow (i.e., more than 2 GB output).
1416+
// * -3 indicates an unrecognized simdutf error.
14171417
staticvoidAtob(const FunctionCallbackInfo<Value>& args) {
14181418
CHECK_EQ(args.Length(), 1);
14191419
Environment* env = Environment::GetCurrent(args);
@@ -1458,7 +1458,7 @@ static void Atob(const FunctionCallbackInfo<Value>& args) {
14581458
return args.GetReturnValue().Set(value);
14591459
}
14601460

1461-
// Default value is: "possible overflow"
1461+
// Default value is: "unrecognized simdutf error"
14621462
int32_t error_code = -3;
14631463

14641464
if (result.error == simdutf::error_code::INVALID_BASE64_CHARACTER) {

0 commit comments

Comments
 (0)