3

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?

Goblaz
  • 53
  • 1
  • 8
  • According to [this answer](https://stackoverflow.com/q/17823225/1048572), it's implementation-dependent. What browser on what system are you using? – Bergi Oct 23 '18 at 19:06
  • I'm using Chrome Version 69.0.3497.100 (Official Build) (32-bit) on a windows 10 enterprise 64-bit with 16 gigs of ram – Goblaz Oct 23 '18 at 19:10
  • 1
    i didn't even think browser js allowed access to gigs of ram... – dandavis Oct 23 '18 at 19:31
  • I'm getting "RangeError: Invalid typed array length: 40". From this: new Float64Array(window.Module.HEAPF64.buffer, pointer, 40); HEAPF64 is another typed array, length 2097152. Pointer is 5276224. This has been working correctly for months. Maybe it's time to reboot. Or, take a vacation. – OsamaBinLogin Dec 25 '22 at 07:39
  • It was off the end. So, it's not just the length that can cause an error. – OsamaBinLogin Dec 25 '22 at 07:48

1 Answers1

0

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
visibleman
  • 3,175
  • 1
  • 14
  • 27