GeezerVison is showing github.com — lib: fix compileFunction throws range error for negative numbers · nodejs/node@d9c791a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/vm.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,9 +16,9 @@ const { | 16 | 16 | validateObject, | 17 | 17 | validateString, | 18 | 18 | validateStringArray, | 19 | | - validateUint32, | 20 | 19 | kValidateObjectAllowArray, | 21 | 20 | kValidateObjectAllowNullable, | | 21 | + validateInt32, | 22 | 22 | } = require('internal/validators'); | 23 | 23 | const { | 24 | 24 | ERR_INVALID_ARG_TYPE, | @@ -48,8 +48,8 @@ function internalCompileFunction(code, params, options) { | 48 | 48 | } = options; | 49 | 49 |
| 50 | 50 | validateString(filename, 'options.filename'); | 51 | | - validateUint32(columnOffset, 'options.columnOffset'); | 52 | | - validateUint32(lineOffset, 'options.lineOffset'); | | 51 | + validateInt32(columnOffset, 'options.columnOffset'); | | 52 | + validateInt32(lineOffset, 'options.lineOffset'); | 53 | 53 | if (cachedData !== undefined) | 54 | 54 | validateBuffer(cachedData, 'options.cachedData'); | 55 | 55 | validateBoolean(produceCachedData, 'options.produceCachedData'); | |
Collapse file Copy file name to clipboard +34Lines changed: 34 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +); |
|