assert: cap input size in myersDiff to avoid Int32Array overflow · nodejs/node@d913872

Original file line numberDiff line numberDiff line change

@@ -6,6 +6,12 @@ const {

66

StringPrototypeEndsWith,

77

} = primordials;

88
9+

const {

10+

codes: {

11+

ERR_OUT_OF_RANGE,

12+

},

13+

} = require('internal/errors');

14+
915

const colors = require('internal/util/colors');

1016
1117

const kNopLinesToCollapse = 5;

@@ -29,7 +35,15 @@ function myersDiff(actual, expected, checkCommaDisparity = false) {

2935

const actualLength = actual.length;

3036

const expectedLength = expected.length;

3137

const max = actualLength + expectedLength;

32-

// TODO(BridgeAR): Cap the input in case the values go beyond the limit of 2^31 - 1.

38+
39+

if (max > 2 ** 31 - 1) {

40+

throw new ERR_OUT_OF_RANGE(

41+

'myersDiff input size',

42+

'< 2^31',

43+

max,

44+

);

45+

}

46+
3347

const v = new Int32Array(2 * max + 1);

3448

const trace = [];

3549