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

Disallow ArrayBuffers bigger than 2**53 #1032

Open
littledan opened this Issue Nov 17, 2017 · 9 comments

Comments

Projects
None yet
6 participants
@littledan
Member

littledan commented Nov 17, 2017

As pointed out by @verwaest, weird things happen on gigantic ArrayBuffers, where you can't actually address each byte because Numbers can't point to things bigger than 2**53. @verwaest points out a case in interactions with BigInt, but I think there are more mundane cases as well (e.g., running any of the array-derived methods, which assume that you can increment a Number up to the length of the TypedArray).

This is probably not reachable in real implementations because CreateByteDataBlock will throw a RangeError on too-big arguments. I think we should change the specification to throw if you're above 2**53 to prevent the theoretical case where you get outside exact integer territory. Some callsites of CreateByteDataBlock call ToIndex (which will always be in that range) but some don't (e.g., TypedArray constructors called on iterables, though that would take forever). Maybe this could be fixed by inserting more calls to ToIndex.

@rossberg

This comment has been minimized.

Show comment
Hide comment
@rossberg

rossberg Nov 17, 2017

Member

Note that once WebAssembly supports 64-bit address spaces, one of its linear memories might (just as theoretically) be larger than 2^53. So it would no longer be possible to materialise every memory as an ArrayBuffer in JavaScript under that restriction.

Member

rossberg commented Nov 17, 2017

Note that once WebAssembly supports 64-bit address spaces, one of its linear memories might (just as theoretically) be larger than 2^53. So it would no longer be possible to materialise every memory as an ArrayBuffer in JavaScript under that restriction.

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Nov 17, 2017

Member

I think we're pretty far in the future to get beyond 2^53 bits of memory. We won't be able to use a Number to store things anyway. (Seems like I misunderstood the idea of the other post, clarification)

Member

littledan commented Nov 17, 2017

I think we're pretty far in the future to get beyond 2^53 bits of memory. We won't be able to use a Number to store things anyway. (Seems like I misunderstood the idea of the other post, clarification)

@rossberg

This comment has been minimized.

Show comment
Hide comment
@rossberg

rossberg Nov 17, 2017

Member

Well, we talked about things like supporting mmap and other virtual memory games, so I'm not so sure.

Member

rossberg commented Nov 17, 2017

Well, we talked about things like supporting mmap and other virtual memory games, so I'm not so sure.

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Nov 17, 2017

Member

My understanding was that virtual memory in 64-bit systems was commonly a 48-bit address space.

Member

littledan commented Nov 17, 2017

My understanding was that virtual memory in 64-bit systems was commonly a 48-bit address space.

@allenwb

This comment has been minimized.

Show comment
Hide comment
@allenwb

allenwb Nov 17, 2017

Member

virtual memory in 64-bit systems was commonly a 48-bit address space.

In which decade?

Member

allenwb commented Nov 17, 2017

virtual memory in 64-bit systems was commonly a 48-bit address space.

In which decade?

@jfbastien

This comment has been minimized.

Show comment
Hide comment
@jfbastien

jfbastien Nov 17, 2017

virtual memory in 64-bit systems was commonly a 48-bit address space.

In which decade?

The current decade.

jfbastien commented Nov 17, 2017

virtual memory in 64-bit systems was commonly a 48-bit address space.

In which decade?

The current decade.

@apaprocki

This comment has been minimized.

Show comment
Hide comment
@apaprocki

apaprocki Nov 17, 2017

Contributor

... to clarify the above, AMD64 architecture defines a 64-bit virtual address format, of which the low-order 48 bits are used in current implementations.

Don't take it too seriously, but both POWER (Node.js ships for POWER) and SPARC actually use the 64-bit address space and I will admit to having to force memory allocated for SpiderMonkey to fit under the 48-bit limit to not break invariants in the engine. Intel domination creeping into software design... :)

Contributor

apaprocki commented Nov 17, 2017

... to clarify the above, AMD64 architecture defines a 64-bit virtual address format, of which the low-order 48 bits are used in current implementations.

Don't take it too seriously, but both POWER (Node.js ships for POWER) and SPARC actually use the 64-bit address space and I will admit to having to force memory allocated for SpiderMonkey to fit under the 48-bit limit to not break invariants in the engine. Intel domination creeping into software design... :)

@allenwb

This comment has been minimized.

Show comment
Hide comment
@allenwb

allenwb Nov 17, 2017

Member

@jfbastien
I hope my irony was obvious. Never write standards for the current decade.

Member

allenwb commented Nov 17, 2017

@jfbastien
I hope my irony was obvious. Never write standards for the current decade.

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Nov 18, 2017

Member

@apaprocki Thanks for that context. I wasn't aware of POWER and SPARC. Still, everything with using ArrayBuffers is currently tied to Number, so until we upgrade them to BigInt, I still think we should do this sort of change.

Member

littledan commented Nov 18, 2017

@apaprocki Thanks for that context. I wasn't aware of POWER and SPARC. Still, everything with using ArrayBuffers is currently tied to Number, so until we upgrade them to BigInt, I still think we should do this sort of change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment