Skip to content

Commit

Permalink
Handle out-of-bound access in TypedArray
Browse files Browse the repository at this point in the history
Signed-off-by: HyukWoo Park <[email protected]>
  • Loading branch information
clover2123 committed Dec 10, 2024
1 parent a02c48d commit 7554270
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 114 deletions.
12 changes: 6 additions & 6 deletions src/builtins/BuiltinTypedArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,20 +763,20 @@ static Value builtinTypedArraySet(ExecutionState& state, Value thisValue, size_t
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, strings->TypedArray.string(), true, strings->set.string(), ErrorObject::Messages::GlobalObject_InvalidArrayLength);
}

size_t targetByteIndex = targetOffset * targetElementSize + targetByteOffset;
size_t k = 0;
size_t limit = targetByteIndex + targetElementSize * srcLength;
while (targetByteIndex < limit) {
size_t targetByteIndex = targetOffset * targetElementSize + targetByteOffset;
while (k < srcLength) {
Value value = src->get(state, ObjectPropertyName(state, Value(k))).value(state, src);

if (UNLIKELY(isBigIntArray)) {
value = value.toBigInt(state);
} else {
value = Value(Value::DoubleToIntConvertibleTestNeeds, value.toNumber(state));
}
targetBuffer->throwTypeErrorIfDetached(state);

// Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, value, true, "Unordered").
targetBuffer->setValueInBuffer(state, targetByteIndex, target->typedArrayType(), value);
if (LIKELY(!targetBuffer->isDetachedBuffer() && targetByteIndex + targetElementSize <= targetBuffer->byteLength())) {
targetBuffer->setValueInBuffer(state, targetByteIndex, target->typedArrayType(), value);
}

k++;
targetByteIndex += targetElementSize;
Expand Down
Loading

0 comments on commit 7554270

Please sign in to comment.