Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb7b78fd

Browse files
haramjrichardlau
authored andcommitted
assert: cap input size in myersDiff to avoid Int32Array overflow
PR-URL:#59578Reviewed-By: James M Snell <jasnell@gmail.com>Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parentf660943 commitb7b78fd

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

‎lib/internal/assert/myers_diff.js‎

Lines changed: 15 additions & 1 deletion
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
constcolors=require('internal/util/colors');
1016

1117
constkNopLinesToCollapse=5;
@@ -29,7 +35,15 @@ function myersDiff(actual, expected, checkCommaDisparity = false) {
2935
constactualLength=actual.length;
3036
constexpectedLength=expected.length;
3137
constmax=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+
thrownewERR_OUT_OF_RANGE(
41+
'myersDiff input size',
42+
'< 2^31',
43+
max,
44+
);
45+
}
46+
3347
constv=newInt32Array(2*max+1);
3448
consttrace=[];
3549

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
4+
constcommon=require('../common');
5+
constassert=require('assert');
6+
7+
const{ myersDiff}=require('internal/assert/myers_diff');
8+
9+
{
10+
constarr1={length:2**31-1};
11+
constarr2={length:2};
12+
constmax=arr1.length+arr2.length;
13+
assert.throws(
14+
()=>{
15+
myersDiff(arr1,arr2);
16+
},
17+
common.expectsError({
18+
code:'ERR_OUT_OF_RANGE',
19+
name:'RangeError',
20+
message:'The value of "myersDiff input size" '+
21+
'is out of range. It must be < 2^31. '+
22+
`Received${max}`
23+
})
24+
);
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp