Skip to content

Commit

Permalink
lib: fix compileFunction throws range error for negative numbers
Browse files Browse the repository at this point in the history
PR-URL: #49855
Fixes: #49848
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
MrJithil authored and targos committed Nov 11, 2023
1 parent fee8b24 commit d9c791a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/internal/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const {
validateObject,
validateString,
validateStringArray,
validateUint32,
kValidateObjectAllowArray,
kValidateObjectAllowNullable,
validateInt32,
} = require('internal/validators');
const {
ERR_INVALID_ARG_TYPE,
Expand Down Expand Up @@ -48,8 +48,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');
Expand Down
34 changes: 34 additions & 0 deletions test/es-module/test-vm-compile-function-lineoffset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

require('../common');

const assert = require('assert');
const { compileFunction } = require('node:vm');

const min = -2147483648;
const max = 2147483647;

compileFunction('', [], { lineOffset: min, columnOffset: min });
compileFunction('', [], { lineOffset: max, columnOffset: max });

assert.throws(
() => {
compileFunction('', [], { lineOffset: min - 1, columnOffset: max });
},
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /The value of "options\.lineOffset" is out of range/,
}
);

assert.throws(
() => {
compileFunction('', [], { lineOffset: min, columnOffset: min - 1 });
},
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /The value of "options\.columnOffset" is out of range/,
}
);

0 comments on commit d9c791a

Please sign in to comment.