Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d4c5fe4

Browse filesBrowse files
authored
lib: fix compileFunction throws range error for negative numbers
PR-URL: #49855 Fixes: #49848 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 2fe511b commit d4c5fe4
Copy full SHA for d4c5fe4

File tree

Expand file treeCollapse file tree

2 files changed

+37
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+37
-3
lines changed
Open diff view settings
Collapse file

‎lib/internal/vm.js‎

Copy file name to clipboardExpand all lines: lib/internal/vm.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const {
1616
validateObject,
1717
validateString,
1818
validateStringArray,
19-
validateUint32,
2019
kValidateObjectAllowArray,
2120
kValidateObjectAllowNullable,
21+
validateInt32,
2222
} = require('internal/validators');
2323
const {
2424
ERR_INVALID_ARG_TYPE,
@@ -48,8 +48,8 @@ function internalCompileFunction(code, params, options) {
4848
} = options;
4949

5050
validateString(filename, 'options.filename');
51-
validateUint32(columnOffset, 'options.columnOffset');
52-
validateUint32(lineOffset, 'options.lineOffset');
51+
validateInt32(columnOffset, 'options.columnOffset');
52+
validateInt32(lineOffset, 'options.lineOffset');
5353
if (cachedData !== undefined)
5454
validateBuffer(cachedData, 'options.cachedData');
5555
validateBoolean(produceCachedData, 'options.produceCachedData');
Collapse file
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const assert = require('assert');
6+
const { compileFunction } = require('node:vm');
7+
8+
const min = -2147483648;
9+
const max = 2147483647;
10+
11+
compileFunction('', [], { lineOffset: min, columnOffset: min });
12+
compileFunction('', [], { lineOffset: max, columnOffset: max });
13+
14+
assert.throws(
15+
() => {
16+
compileFunction('', [], { lineOffset: min - 1, columnOffset: max });
17+
},
18+
{
19+
code: 'ERR_OUT_OF_RANGE',
20+
name: 'RangeError',
21+
message: /The value of "options\.lineOffset" is out of range/,
22+
}
23+
);
24+
25+
assert.throws(
26+
() => {
27+
compileFunction('', [], { lineOffset: min, columnOffset: min - 1 });
28+
},
29+
{
30+
code: 'ERR_OUT_OF_RANGE',
31+
name: 'RangeError',
32+
message: /The value of "options\.columnOffset" is out of range/,
33+
}
34+
);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.