Use-after-free in TypedArray.sort
There is a use-after-free in TypedArray.sort. In TypedArrayCompareElementsHelper, the comparison function is called with the following code: Var retVal = CALL_FUNCTION(compFn, CallInfo(CallFlags_Value, 3), undefined, JavascriptNumber::ToVarWithCheck((double)x, scriptContext), JavascriptNumber::ToVarWithCheck((double)y, scriptContext)). Assert(TypedArrayBase::Is(contextArray[0])); if (TypedArrayBase::IsDetachedTypedArray(contextArray[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_DetachedTypedArray, _u("[TypedArray].prototype.sort")); } if (TaggedInt::Is(retVal)) { return TaggedInt::ToInt32(retVal); } if (JavascriptNumber::Is_NoTaggedIntCheck(retVal)) { dblResult = JavascriptNumber::GetValue(retVal); } else { dblResult = JavascriptConversion::ToNumber_Full(retVal, scriptContext); }. The TypeArray is checked to see if it has been detached, but then the return value from the function is converted to an integer, which can invoke valueOf. If this function detaches the TypedArray, one swap is perfomed on the buffer after it is freed.