@@ -981,6 +981,25 @@ namespace Js
981
981
&InterpreterStackFrame::OP_LdArr<int32, int64>,
982
982
&InterpreterStackFrame::OP_LdArr<uint32, int64>,
983
983
};
984
+
985
+ const int InterpreterStackFrame::TypeToSizeMap[] =
986
+ {
987
+ /* int8*/ 1 ,
988
+ /* uint8*/ 1 ,
989
+ /* int16*/ 2 ,
990
+ /* uint16*/ 2 ,
991
+ /* int32*/ 4 ,
992
+ /* uint32*/ 4 ,
993
+ /* float*/ 4 ,
994
+ /* double*/ 8 ,
995
+ /* int64*/ 8 ,
996
+ /* int8*/ 1 ,
997
+ /* uint8*/ 1 ,
998
+ /* int16*/ 2 ,
999
+ /* uint16*/ 2 ,
1000
+ /* int32*/ 4 ,
1001
+ /* uint32*/ 4 ,
1002
+ };
984
1003
#endif
985
1004
986
1005
Var InterpreterStackFrame::InnerScopeFromRegSlot (RegSlot reg) const
@@ -8304,7 +8323,7 @@ const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(const byte * ip)
8304
8323
CompileAssert (Js::ArrayBufferView::TYPE_COUNT == (sizeof (InterpreterStackFrame::LdArrFunc) / sizeof (InterpreterStackFrame::ArrFunc)));
8305
8324
JavascriptArrayBuffer* arr = *(JavascriptArrayBuffer**)GetNonVarReg (AsmJsFunctionMemory::ArrayBufferRegister);
8306
8325
BYTE* buffer = arr->GetBuffer ();
8307
- ArrayType val = index < (arr->GetByteLength ()) ? *(ArrayType*)(buffer + index) : GetArrayViewOverflowVal<ArrayType>();
8326
+ ArrayType val = index + sizeof (ArrayType) < (arr->GetByteLength ()) ? *(ArrayType*)(buffer + index) : GetArrayViewOverflowVal<ArrayType>();
8308
8327
SetRegRaw<RegType>(regSlot, (RegType)val);
8309
8328
}
8310
8329
#endif
@@ -8341,13 +8360,13 @@ const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(const byte * ip)
8341
8360
void InterpreterStackFrame::OP_LdArrWasm (const unaligned T* playout)
8342
8361
{
8343
8362
Assert (playout->ViewType < Js::ArrayBufferView::TYPE_COUNT);
8344
- const uint32 index = (uint32 )GetRegRawInt (playout->SlotIndex );
8363
+ const uint64 index = (uint64 )GetRegRawInt (playout->SlotIndex );
8345
8364
JavascriptArrayBuffer* arr = *(JavascriptArrayBuffer**)GetNonVarReg (AsmJsFunctionMemory::ArrayBufferRegister);
8346
- if (index >= arr->GetByteLength ())
8365
+ if (index >= arr->GetByteLength () || index + TypeToSizeMap[playout-> ViewType ] > arr-> GetByteLength () )
8347
8366
{
8348
8367
JavascriptError::ThrowRangeError (scriptContext, JSERR_InvalidTypedArrayIndex);
8349
8368
}
8350
- (this ->*LdArrFunc[playout->ViewType ])(index, playout->Value );
8369
+ (this ->*LdArrFunc[playout->ViewType ])((uint32) index, playout->Value );
8351
8370
}
8352
8371
template <class T >
8353
8372
void InterpreterStackFrame::OP_LdArrConstIndex (const unaligned T* playout)
@@ -8369,7 +8388,7 @@ const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(const byte * ip)
8369
8388
Assert (playout->ViewType < Js::ArrayBufferView::TYPE_COUNT);
8370
8389
const uint32 index = (uint32)GetRegRawInt (playout->SlotIndex );
8371
8390
JavascriptArrayBuffer* arr = *(JavascriptArrayBuffer**)GetNonVarReg (AsmJsFunctionMemory::ArrayBufferRegister);
8372
- if (index >= arr->GetByteLength ())
8391
+ if (index >= arr->GetByteLength () || index + TypeToSizeMap[playout-> ViewType ] > arr-> GetByteLength () )
8373
8392
{
8374
8393
JavascriptError::ThrowRangeError (scriptContext, JSERR_InvalidTypedArrayIndex);
8375
8394
}
0 commit comments