From 0639d6599c2ad7ef6d1c69d47224f7f7fa917546 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 8c17b158222672..aef7eb41879bf5 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -37,6 +37,7 @@ const { ObjectDefineProperty, ObjectPrototypeHasOwnProperty, ObjectSetPrototypeOf, + RangeError, RegExpPrototypeSymbolReplace, StringPrototypeCharCodeAt, StringPrototypeSlice, @@ -1402,8 +1403,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 4f37f866b897f42ed17fd86d163b6cef89eaf631 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 aef7eb41879bf5..f4d9ceb055e9eb 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -37,7 +37,6 @@ const { ObjectDefineProperty, ObjectPrototypeHasOwnProperty, ObjectSetPrototypeOf, - RangeError, RegExpPrototypeSymbolReplace, StringPrototypeCharCodeAt, StringPrototypeSlice, @@ -1403,7 +1402,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 49eef9b00bf5572ad73d33c0cf5a263845f2da72 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 f4d9ceb055e9eb..5029130531d226 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -1401,8 +1401,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 e45a0123b564211cc0de230d93792638c77a9cf1 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 5029130531d226..1f511f1105c94d 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -110,6 +110,8 @@ const { inspect: utilInspect, } = require('internal/util/inspect'); +const assert = require('internal/assert'); + const { codes: { ERR_BUFFER_OUT_OF_BOUNDS, @@ -1401,6 +1403,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 39e840e826350536c6afc316019aad5b98701587 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 1f511f1105c94d..cc213f12dacf42 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -1405,6 +1405,7 @@ function atob(input) { 'InvalidCharacterError'); case -3: assert.fail('Unrecognized simdutf error'); + break; default: return result; } From 128e95d6e19ea65012dba0ac9ba2fc5f45892acd 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 9adb02517efc42..b414d42ef935cb 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -1456,7 +1456,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); @@ -1501,7 +1501,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) {