-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
%TypedArray%.prototype.slice
does not completely account for the original TA's size changing
#3248
Comments
But as you say, |
In the example, we read past the end of the source TA because the starting offset ( But because |
Great catch, @trflynn89. Will have a PR up shortly. |
Closes tc39#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.)
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.The text was updated successfully, but these errors were encountered: