You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OnReservedCapacityChanged unmaps the file, calls FileHelpers.SetSize and then maps it again. If SetSize (or the remap) throws, the object is left with no mapping: Pointer == IntPtr.Zero, while ReservedCapacity still reports the old value. The next access dereferences null, or garbage when Pointer is cached.
mem-rs fixed the same class of bug in linksplatform/mem-rs#38: on error, the old mapping stays valid.
Reproduction (probe P3)
memory.ReservedCapacity = long.MaxValue / 2 → ArgumentOutOfRangeException: Specified file length was too large for the file system. Afterwards Pointer = 0x0, ReservedCapacity = 4096, file length 4096.
Proposed solution
Validate the new size before unmapping. Reserve and extend the file first (RandomAccess.SetLength / FileStream.SetLength), and only then remap.
On failure, restore the previous mapping (try/catch → MapFile(oldCapacity)) and rethrow. Base-class state must change only after success.
Add a regression test that forces a failure, for example a too-large capacity or a read-only file, and checks that Pointer is still usable.
Activity