Skip to content
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

subarray should check if the output Element Size is the same #2556

Open
petamoriken opened this issue Oct 27, 2021 · 0 comments
Open

subarray should check if the output Element Size is the same #2556

petamoriken opened this issue Oct 27, 2021 · 0 comments

Comments

@petamoriken
Copy link

Since %TypedArray%.prototype.subarray does not check whether the Element Size is the same or not, it can refer to buffers outside the area.

const buffer = new Uint16Array([1, 2, 3, 4]).buffer;
console.log(buffer.byteLength); // => 8

class MyArray extends Uint8Array {
  static get [Symbol.species]() {
    return Uint16Array;
  }
}

const myarr = new MyArray(buffer, 0, 4);
console.log(myarr.byteLength); // => 4

// leaks!
const subarray = myarr.subarray();
console.log(subarray); // => Uint16Array(4) [1, 2, 3, 4]
console.log(subarray.byteLength); // => 8

This behavior is both strange and unhelpful. I think it should be fixed, as it is not expected to cause any large breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant