mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
assert: cap input size in myersDiff to avoid Int32Array overflow
PR-URL: https://github.com/nodejs/node/pull/59578 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
670d7ab7f2
commit
402a02fe2b
|
|
@ -6,6 +6,12 @@ const {
|
||||||
StringPrototypeEndsWith,
|
StringPrototypeEndsWith,
|
||||||
} = primordials;
|
} = primordials;
|
||||||
|
|
||||||
|
const {
|
||||||
|
codes: {
|
||||||
|
ERR_OUT_OF_RANGE,
|
||||||
|
},
|
||||||
|
} = require('internal/errors');
|
||||||
|
|
||||||
const colors = require('internal/util/colors');
|
const colors = require('internal/util/colors');
|
||||||
|
|
||||||
const kNopLinesToCollapse = 5;
|
const kNopLinesToCollapse = 5;
|
||||||
|
|
@ -29,7 +35,15 @@ function myersDiff(actual, expected, checkCommaDisparity = false) {
|
||||||
const actualLength = actual.length;
|
const actualLength = actual.length;
|
||||||
const expectedLength = expected.length;
|
const expectedLength = expected.length;
|
||||||
const max = actualLength + expectedLength;
|
const max = actualLength + expectedLength;
|
||||||
// TODO(BridgeAR): Cap the input in case the values go beyond the limit of 2^31 - 1.
|
|
||||||
|
if (max > 2 ** 31 - 1) {
|
||||||
|
throw new ERR_OUT_OF_RANGE(
|
||||||
|
'myersDiff input size',
|
||||||
|
'< 2^31',
|
||||||
|
max,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const v = new Int32Array(2 * max + 1);
|
const v = new Int32Array(2 * max + 1);
|
||||||
const trace = [];
|
const trace = [];
|
||||||
|
|
||||||
|
|
|
||||||
25
test/parallel/test-assert-myers-diff.js
Normal file
25
test/parallel/test-assert-myers-diff.js
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
// Flags: --expose-internals
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const common = require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const { myersDiff } = require('internal/assert/myers_diff');
|
||||||
|
|
||||||
|
{
|
||||||
|
const arr1 = { length: 2 ** 31 - 1 };
|
||||||
|
const arr2 = { length: 2 };
|
||||||
|
const max = arr1.length + arr2.length;
|
||||||
|
assert.throws(
|
||||||
|
() => {
|
||||||
|
myersDiff(arr1, arr2);
|
||||||
|
},
|
||||||
|
common.expectsError({
|
||||||
|
code: 'ERR_OUT_OF_RANGE',
|
||||||
|
name: 'RangeError',
|
||||||
|
message: 'The value of "myersDiff input size" ' +
|
||||||
|
'is out of range. It must be < 2^31. ' +
|
||||||
|
`Received ${max}`
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user