Repository navigation
vm: vm.compileFunction does not support negative lineOffset and columnOffset #49848
Copy link
Copy link
Closed
Closed
Copy link
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
Description
Activity
(1) is a validation bug and probably also responsible for (2), see diff and PR welcome. Other parts of node do seem to be validating it correctly as an int32, just not lib/internal/vm.js.
Details
diff --git a/lib/internal/vm.js b/lib/internal/vm.js index ba5e232466..111bab8621 100644 --- a/lib/internal/vm.js +++ b/lib/internal/vm.js @@ -13,10 +13,10 @@ const { validateBoolean, validateBuffer, validateFunction, + validateInt32, validateObject, validateString, validateStringArray, - validateUint32, } = require('internal/validators'); const { ERR_INVALID_ARG_TYPE, @@ -46,8 +46,8 @@ function internalCompileFunction(code, params, options) { } = options; validateString(filename, 'options.filename'); - validateUint32(columnOffset, 'options.columnOffset'); - validateUint32(lineOffset, 'options.lineOffset'); + validateInt32(columnOffset, 'options.columnOffset'); + validateInt32(lineOffset, 'options.lineOffset'); if (cachedData !== undefined) validateBuffer(cachedData, 'options.cachedData'); validateBoolean(produceCachedData, 'options.produceCachedData');
- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
on Sep 25, 2023 - addedgood first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
on Sep 25, 2023 Created PR.
- added a commit that references this issue
on Oct 6, 2023 - added a commit that references this issue
on Nov 11, 2023 - added a commit that references this issue
on Mar 15, 2024 - added a commit that references this issue
on Apr 15, 2024
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
Version:
v20.6.1; older versions are also affectedSubsystem
vmCurrent issue:
The
vm.compileFunctionmethod in Node.js currently doesn't support negativelineOffsetandcolumnOffsetvalues.(2^31)-1, causing it to become -2147483637 with the presence of overflow protection measures:Additional information:
The
vm.compileFunctionmethod in Node.js currently doesn't support negativelineOffsetandcolumnOffsetvalues. This is inconsistent with other methods such asvm.runInContext,vm.runInNewContext, andnew vm.Script(), which do support negative values for these parameters.The underlying V8 engine also supports negative values for these parameters as indicated in the
ScriptOriginclass:A common use case for the
lineOffsetoption invm.compileFunctionis to shift lines in error tracebacks to support adding wrappers. Negative values enable the correct line number to be displayed in stack traces when wrapper code is added, while positive values would require part of the code to be removed to get a correct line number, which is not applicable in most scenarios. Hence, negative options are a primary use case that should be supported. An example use case is shown below:Possible solution:
Upon investigation, the cause of this issue can be traced back to this line in
lib/internal/vm.js:node/lib/internal/vm.js
Line 50 in 448996c
A tested and effective solution is to change the
validateUint32function tovalidateInt32for thelineOffsetandcolumnOffsetparameters.