Skip to content

Commit 22de374

Browse files
sygljharb
authored andcommitted
Normative: Recompute count in TA.p.slice (#3255)
Closes #3248. The current algorithm has a bug that can result in OOB reads in the source TA, because _count_ is not correctly recomputed when the source TA is resized during evaluation of the species constructor. (It is currently bounded by _len_, which is recomputed, but this is incorrect because the bounds of the copy loop is not on the length, but instead on how many bytes need to be copied.)
1 parent 92d2410 commit 22de374

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

spec.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41112,6 +41112,7 @@ <h1>%TypedArray%.prototype.slice ( _start_, _end_ )</h1>
4111241112
1. If IsTypedArrayOutOfBounds(_taRecord_) is *true*, throw a *TypeError* exception.
4111341113
1. Set _len_ to TypedArrayLength(_taRecord_).
4111441114
1. Set _final_ to min(_final_, _len_).
41115+
1. Set _count_ to max(_final_ - _k_, 0).
4111541116
1. Let _srcType_ be TypedArrayElementType(_O_).
4111641117
1. Let _targetType_ be TypedArrayElementType(_A_).
4111741118
1. If _srcType_ is _targetType_, then
@@ -41122,7 +41123,7 @@ <h1>%TypedArray%.prototype.slice ( _start_, _end_ )</h1>
4112241123
1. Let _srcByteOffset_ be _O_.[[ByteOffset]].
4112341124
1. Let _srcByteIndex_ be (_k_ × _elementSize_) + _srcByteOffset_.
4112441125
1. Let _targetByteIndex_ be _A_.[[ByteOffset]].
41125-
1. Let _limit_ be _targetByteIndex_ + min(_count_, _len_) × _elementSize_.
41126+
1. Let _limit_ be _targetByteIndex_ + (_count_ × _elementSize_).
4112641127
1. Repeat, while _targetByteIndex_ &lt; _limit_,
4112741128
1. Let _value_ be GetValueFromBuffer(_srcBuffer_, _srcByteIndex_, ~uint8~, *true*, ~unordered~).
4112841129
1. Perform SetValueInBuffer(_targetBuffer_, _targetByteIndex_, ~uint8~, _value_, *true*, ~unordered~).

0 commit comments

Comments
 (0)