lib: fix compileFunction throws range error for negative numbers

PR-URL: https://github.com/nodejs/node/pull/49855
Fixes: https://github.com/nodejs/node/issues/49848
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Jithil P Ponnan 2023-10-07 01:33:46 +11:00 committed by GitHub
parent 2fe511ba23
commit d4c5fe488e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 3 deletions

View file

@ -16,9 +16,9 @@ const {
validateObject,
validateString,
validateStringArray,
validateUint32,
kValidateObjectAllowArray,
kValidateObjectAllowNullable,
validateInt32,
} = require('internal/validators');
const {
ERR_INVALID_ARG_TYPE,
@ -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');

View file

@ -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/,
}
);