Skip to content

Commit f61ea1c

Browse files
MikeHolmanpleath
authored andcommitted
add check against length for memset
1 parent 4928065 commit f61ea1c

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

lib/Runtime/Library/TypedArray.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ namespace Js
331331
// fixup the length with the change
332332
newLength += start;
333333
}
334+
if (newStart >= GetLength())
335+
{
336+
// If we want to start copying past the length of the array, all index are no-op
337+
return true;
338+
}
339+
334340
if (UInt32Math::Add(newStart, newLength) > GetLength())
335341
{
336342
newLength = GetLength() - newStart;

test/typedarray/memset_neg.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
function foo() {
7+
var a = new Int8Array(500);
8+
for(var i = 500; i < 1000; ++i) {
9+
a[i] = 0;
10+
}
11+
}
12+
13+
foo();
14+
foo();
15+
WScript.Echo("PASSED");

test/typedarray/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ Below test fails with difference in space. Investigate the cause and re-enable t
304304
<compile-flags>-mic:1 -off:simplejit -off:JITLoopBody -mmoc:0</compile-flags>
305305
</default>
306306
</test>
307+
<test>
308+
<default>
309+
<files>memset_neg.js</files>
310+
<compile-flags>-mic:1 -off:simplejit -bgjit- -mmoc:0</compile-flags>
311+
</default>
312+
</test>
307313
<test>
308314
<default>
309315
<files>memcopy.js</files>

0 commit comments

Comments
 (0)