From 89b1cf82e0c5320b23c7c667f092c7b5f8d98465 Mon Sep 17 00:00:00 2001 From: semimikoh Date: Thu, 16 Apr 2026 13:42:23 +0900 Subject: [PATCH] src: fix crash in GetErrorSource() for invalid using syntax --- src/node_errors.cc | 4 ++-- test/parallel/test-cli-eval-invalid-using.js | 23 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-cli-eval-invalid-using.js diff --git a/src/node_errors.cc b/src/node_errors.cc index 23ca0bc50f68c6..068b1a7c6d83fb 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -150,8 +150,7 @@ static std::string GetErrorSource(Isolate* isolate, : 0; int start = message->GetStartColumn(context).FromMaybe(0); int end = message->GetEndColumn(context).FromMaybe(0); - if (start >= script_start) { - CHECK_GE(end, start); + if (start >= script_start && end >= script_start) { start -= script_start; end -= script_start; } @@ -163,6 +162,7 @@ static std::string GetErrorSource(Isolate* isolate, if (start > end || start < 0 || + end < 0 || static_cast(end) > sourceline.size()) { return buf; } diff --git a/test/parallel/test-cli-eval-invalid-using.js b/test/parallel/test-cli-eval-invalid-using.js new file mode 100644 index 00000000000000..59a8cf8b6e588f --- /dev/null +++ b/test/parallel/test-cli-eval-invalid-using.js @@ -0,0 +1,23 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const { spawnSyncAndAssert } = require('../common/child_process'); + +[ + '{using x=null, []=null;}', + '{using x=null, {}=null;}', + 'async function f() { { await using x=null, []=null; } }', + 'async function f() { { await using x=null, {}=null; } }', +].forEach((script) => { + spawnSyncAndAssert(process.execPath, ['--eval', script], { + status: 1, + signal: null, + stderr(output) { + assert.match(output, /SyntaxError/); + assert.doesNotMatch(output, /Assertion failed/); + assert.doesNotMatch(output, /Native stack trace/); + }, + stdout: '', + }); +});