slice & other TypedArray.prototype funcs: shouldn't we reload the length? #73
Description
The problem occurs when
- We're using a length tracking TypedArray and calling TypedArray.prototype.slice
- ToIntegerOrInfinity, TypedArraySpeciesCreate etc. calls user code which shrinks the underlying buffer
Example:
let ab = new ArrayBuffer(4, {maxByteLength: 8});
let ta = new Uint8Array(ab); // Length-tracking, offset 0
let evil = { valueOf: () => { rab.resize(2); return 0;}};
ta.slice(evil);
Now:
Step 3: len = 4
Step 4: calling ToIntegerOrInfinity resizes, relativeStart = 0
Step 6: k = 4
Step 8: relativeEnd = 4
Step 11: final = 4
Step 12: count = 4
Step 14 a, b, c do the detachedness & OOB checks. Now the TA is not OOB since it's length tracking.
Step 14.i.ix.1 ends up reading out of bounds memory.
I'm not sure what the cleanest solution is. Do we need to reload the length and do all the computations again? Do we want to reload the length and if it has changed, throw?
This problem probably happens for many TypedArray.prototype functions.