Skip to content

Commit a483bfd

Browse files
haramjrichardlau
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 da88f70 commit a483bfd

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
@@ -110,6 +110,8 @@ const {
110110
inspect: utilInspect,
111111
} = require('internal/util/inspect');
112112

113+
const assert = require('internal/assert');
114+
113115
const {
114116
codes: {
115117
ERR_BUFFER_OUT_OF_BOUNDS,
@@ -1401,9 +1403,9 @@ function atob(input) {
14011403
throw lazyDOMException(
14021404
'The string to be decoded is not correctly encoded.',
14031405
'InvalidCharacterError');
1404-
case -3: // Possible overflow
1405-
// TODO(@anonrig): Throw correct error in here.
1406-
throw lazyDOMException('The input causes overflow.', 'InvalidCharacterError');
1406+
case -3:
1407+
assert.fail('Unrecognized simdutf error');
1408+
break;
14071409
default:
14081410
return result;
14091411
}

src/node_buffer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ static void Btoa(const FunctionCallbackInfo<Value>& args) {
15121512
// In case of error, a negative value is returned:
15131513
// * -1 indicates a single character remained,
15141514
// * -2 indicates an invalid character,
1515-
// * -3 indicates a possible overflow (i.e., more than 2 GB output).
1515+
// * -3 indicates an unrecognized simdutf error.
15161516
static void Atob(const FunctionCallbackInfo<Value>& args) {
15171517
CHECK_EQ(args.Length(), 1);
15181518
Environment* env = Environment::GetCurrent(args);
@@ -1557,7 +1557,7 @@ static void Atob(const FunctionCallbackInfo<Value>& args) {
15571557
return args.GetReturnValue().Set(value);
15581558
}
15591559

1560-
// Default value is: "possible overflow"
1560+
// Default value is: "unrecognized simdutf error"
15611561
int32_t error_code = -3;
15621562

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

0 commit comments

Comments
 (0)