Uint8Array invalid typed array length for larger array buffer

Viewed 3046

I'm reading a file as an array buffer via:

reader.readAsArrayBuffer(myFile);

I'm then taking that array buffer and trying to create a Uint8Array via:

reader.onload = e => {
  let arrayBuffer = new Uint8Array(e.target.result, 0, 
  e.target.result.byteLength);

I've also tried just:

let arrayBuffer = new Uint8Array(e.target.result);

In both cases when I upload a file with a byte length of 198873088 it works fine. However when I try a larger file of 1564725248 i get the following in the first case:

Invalid typed array length: 1564725248

and this in the second case:

Invalid typed array length: undefined

I thought the cap was 2^32 - 1 which would be 42949672995, can anyone explain why there's a problem with the length?

1 Answers

In latest Chrome Version 71.0.3578.98 (Official Build) (64-bit), I get the following results. Each test performed after a hard reload on blank page.

a=new Uint8Array(256*256*256*128) // Triggers Uncaught RangeError: Invalid typed array length: 2147483648
a=new Uint8Array(256*256*256*127) // Works, array length 2130706432

However more interesting is that I can trigger an "Aw, Snap" without getting the exception. :

a=new Uint8Array(256*256*256*127 + 64) // Doesn't work, triggers "Aw, Snap!" page
Related