Skip to content
Merged
Changes from 1 commit
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
Next Next commit
assert: cap input size in myersDiff to avoid Int32Array overflow
  • Loading branch information
haramj committed Aug 22, 2025
commit c49523edcc8ef415a906f1f516173c2fd2dc7422
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 > 0x7FFFFFFF) {
throw new ERR_OUT_OF_RANGE(
'myersDiff input size',
'< 2^31 - 1',
max,
);
}

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

Expand Down
Loading