Bug 260017
Summary: | RangeError: Out of memory when creating (Shared)ArrayBuffer with big maxByteLength | ||
---|---|---|---|
Product: | WebKit | Reporter: | Joonas Lipping <jl.public.32> |
Component: | WebAssembly | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED WONTFIX | ||
Severity: | Normal | CC: | d_degazio, jl.public.32, keith_miller, mark.lam, webkit-bug-importer, ysuzuki |
Priority: | P2 | Keywords: | InRadar |
Version: | Safari 16 | ||
Hardware: | iPhone / iPad | ||
OS: | iOS 16 |
Joonas Lipping
When creating an ArrayBuffer or SharedArrayBuffer with a small length but a large maxByteLength, for example:
new ArrayBuffer(64 * 1024, { maxByteLength: 4 * 1024 * 1024 * 1024 })
or
new SharedArrayBuffer(64 * 1024, { maxByteLength: 4 * 1024 * 1024 * 1024 })
a RangeError: Out of memory occurs, as if we are trying to allocate the whole 4GiB immediately.
I would expect that the buffer would initially be created successfully with 64kiB of memory, but a subsequent grow() might fail, if it exceeds available memory.
If I reduce the requested maxByteLength to e.g. 4MiB instead, it successfully creates the buffer.
I think this only occurs if the device has less memory available than the maxByteLength that we give as an argument. On the iPhone SE (2020) that I have, the exception always occurs if I request maxByteLength as 4GiB, but on the laptop it's fine, presumably because the laptop has that much memory to spare.
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/114012792>
Mark Lam
I don't think there's anything in the spec that says a device must give you the requested maxByteLength. There are many different constraints in a system as to why this is not workable.
Does any other phone devices behave differently and allow a request for 4G of max capacity?
Yusuke Suzuki
Yes, this is expected behavior. Growable DharedArrayBuffer is designed to allocate virtual memory region with maxByteLength (to allow concurrent access to grown memory), and this means that we need to allocate that from the beginning (the spec itself is designed so) So large size can fail, and expected.