Closed trflynn89 closed 10 months ago
But as you say, len
is updated, and limit
(used for bounding the loop) is computed from the smaller of count
and len
, so I don't see how srcByteIndex
would go past the end of the source TA.
In the example, we read past the end of the source TA because the starting offset (k
) is 1. Since len
becomes 2, we only have 1 slot left to read from. So limit
should be 1.
But because count
wasn't updated, when we set limit
, we have limit = min(count, len) = min(2, 2)
, thus we think we have 2 slots available to read from.
Great catch, @trflynn89. Will have a PR up shortly.
In
%TypedArray%.prototype.slice
, it is possible for the source TA's size to change, for example during the13. Let A be ? TypedArraySpeciesCreate(O, « 𝔽(count) »).
step. The spec partially handles this case by updating a few locals before later writing to the new TA:However, these steps do not update the
count
value, which was previously initialized as:This causes an issue later while reading values from the source TA:
In the call to
GetValueFromBuffer
, becausecount
was not updated, it is possible to read from an index that is past-the-end of thesrcBuffer
.This is observable with the following JS, which I reduced from the
test/staging/ArrayBuffer/resizable/slice-species-create-resizes.js
test262 test case:In the call to
slice
, the size of the source TA is reduced from 4 to 2 during the13. TypedArraySpeciesCreate
step. Before that step, we havek=1
,final=3
,len=4
,count=2
. After step 14d, we havek=1
,final=2
,len=2
. Becausecount
is not updated, it is stillcount=2
. This leads to reading one past-the-end of the source TA buffer.