Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/internal/assert/myers_diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const {
StringPrototypeEndsWith,
} = primordials;

const {
codes: {
ERR_OUT_OF_RANGE,
},
} = require('internal/errors');

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

const kNopLinesToCollapse = 5;
Expand All @@ -29,7 +35,15 @@ function myersDiff(actual, expected, checkCommaDisparity = false) {
const actualLength = actual.length;
const expectedLength = expected.length;
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 trace = [];

Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-assert-myers-diff.js
Original file line number Diff line number Diff line change
@@ -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