From e3fae16d0a360bb4958dcd565ef0e30ad784df8d Mon Sep 17 00:00:00 2001 From: haramjeong <04harams77@gmail.com> Date: Wed, 8 Oct 2025 15:38:07 +0900 Subject: [PATCH 1/6] buffer: throw RangeError on atob overflow Signed-off-by: haramjeong <04harams77@gmail.com> --- lib/buffer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index c9f45d333886d3..0e7e9b7e33e2a8 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -37,6 +37,7 @@ const { ObjectDefineProperty, ObjectPrototypeHasOwnProperty, ObjectSetPrototypeOf, + RangeError, RegExpPrototypeSymbolReplace, StringPrototypeCharCodeAt, StringPrototypeSlice, @@ -1303,8 +1304,7 @@ function atob(input) { 'The string to be decoded is not correctly encoded.', 'InvalidCharacterError'); case -3: // Possible overflow - // TODO(@anonrig): Throw correct error in here. - throw lazyDOMException('The input causes overflow.', 'InvalidCharacterError'); + throw new RangeError('The string to be decoded is too long.'); default: return result; } From a6443cd11e4402c161380e655ebfc99735793815 Mon Sep 17 00:00:00 2001 From: haramjeong <04harams77@gmail.com> Date: Wed, 8 Oct 2025 15:50:31 +0900 Subject: [PATCH 2/6] buffer: fix lint-js Signed-off-by: haramjeong <04harams77@gmail.com> --- lib/buffer.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index 0e7e9b7e33e2a8..655e3843e75acb 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -37,7 +37,6 @@ const { ObjectDefineProperty, ObjectPrototypeHasOwnProperty, ObjectSetPrototypeOf, - RangeError, RegExpPrototypeSymbolReplace, StringPrototypeCharCodeAt, StringPrototypeSlice, @@ -1304,7 +1303,7 @@ function atob(input) { 'The string to be decoded is not correctly encoded.', 'InvalidCharacterError'); case -3: // Possible overflow - throw new RangeError('The string to be decoded is too long.'); + throw new ERR_INVALID_ARG_VALUE('input', result, 'The string to be decoded is too long.'); default: return result; } From 8d62e7d8bf647c0ad088677f8ba0e2ab80e47e42 Mon Sep 17 00:00:00 2001 From: Haram Jeong <91401364+haramj@users.noreply.github.com> Date: Sun, 12 Oct 2025 14:41:06 +0900 Subject: [PATCH 3/6] buffer: remove unreachable overflow check in atob Signed-off-by: haramjeong <04harams77@gmail.com> --- lib/buffer.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index 655e3843e75acb..c955bb931bad69 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -1302,8 +1302,6 @@ function atob(input) { throw lazyDOMException( 'The string to be decoded is not correctly encoded.', 'InvalidCharacterError'); - case -3: // Possible overflow - throw new ERR_INVALID_ARG_VALUE('input', result, 'The string to be decoded is too long.'); default: return result; } From ac83b9d8eb6570848731dca6347642565e1624a6 Mon Sep 17 00:00:00 2001 From: haramjeong <04harams77@gmail.com> Date: Mon, 13 Oct 2025 10:01:37 +0900 Subject: [PATCH 4/6] buffer: add assert.fail() Signed-off-by: haramjeong <04harams77@gmail.com> --- lib/buffer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/buffer.js b/lib/buffer.js index c955bb931bad69..af9d104f42786c 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -99,6 +99,8 @@ const { inspect: utilInspect, } = require('internal/util/inspect'); +const assert = require('internal/assert'); + const { codes: { ERR_BUFFER_OUT_OF_BOUNDS, @@ -1302,6 +1304,8 @@ function atob(input) { throw lazyDOMException( 'The string to be decoded is not correctly encoded.', 'InvalidCharacterError'); + case -3: + assert.fail('Unrecognized simdutf error'); default: return result; } From 387cb0c7023c28fd11c445d755d12de4dad3d9c9 Mon Sep 17 00:00:00 2001 From: haramjeong <04harams77@gmail.com> Date: Mon, 13 Oct 2025 10:08:52 +0900 Subject: [PATCH 5/6] buffer: fix lint error Signed-off-by: haramjeong <04harams77@gmail.com> --- lib/buffer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/buffer.js b/lib/buffer.js index af9d104f42786c..7cce07ddc5d410 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -1306,6 +1306,7 @@ function atob(input) { 'InvalidCharacterError'); case -3: assert.fail('Unrecognized simdutf error'); + break; default: return result; } From ca418cc9a648bb757a41a0dd3a16b15f98b3c46c Mon Sep 17 00:00:00 2001 From: haramjeong <04harams77@gmail.com> Date: Sat, 6 Jun 2026 20:22:58 +0900 Subject: [PATCH 6/6] buffer: update atob error code comments Signed-off-by: haramjeong <04harams77@gmail.com> --- src/node_buffer.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 0e4d437c1ea501..8dd88948cb827f 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -1341,7 +1341,7 @@ static void Btoa(const FunctionCallbackInfo& args) { // In case of error, a negative value is returned: // * -1 indicates a single character remained, // * -2 indicates an invalid character, -// * -3 indicates a possible overflow (i.e., more than 2 GB output). +// * -3 indicates an unrecognized simdutf error. static void Atob(const FunctionCallbackInfo& args) { CHECK_EQ(args.Length(), 1); Environment* env = Environment::GetCurrent(args); @@ -1386,7 +1386,7 @@ static void Atob(const FunctionCallbackInfo& args) { return args.GetReturnValue().Set(value); } - // Default value is: "possible overflow" + // Default value is: "unrecognized simdutf error" int32_t error_code = -3; if (result.error == simdutf::error_code::INVALID_BASE64_CHARACTER) {