FileAccess.StoreBuffer() crashes in exported project only

Godot Version

Godot v4.5.1.stable.mono - Windows 10 (build 19045)

Question

My game runs just fine in the editor. However, when I export the project, it crashes while downloading a ZIP file from a website. The HTTPRequest completes and returns a byte[] to my signal handler, and I create a new FileAccess object to store it on the disk so I can unzip it.

However, instead of storing the buffer in the newly-created file, the exported project crashes with the following error:

ERROR: Parameter “mem_new” is null.
at: _alloc (./core/templates/cowdata.h:384)
C# backtrace (most recent call first):
[0]
[1]
[2]
[3]
[4]
[5]
Fatal error. 0xC0000005
at Godot.NativeInterop.NativeFuncs.godotsharp_packed_byte_array_new_mem_copy(Byte*, Int32)
at Godot.NativeInterop.Marshaling.ConvertSystemArrayToNativePackedByteArray(System.ReadOnlySpan`1)
at Godot.NativeCalls.godot_icall_1_563(IntPtr, IntPtr, System.ReadOnlySpan`1)
at Godot.FileAccess.StoreBuffer(Byte)

This appears to be caused by this interop function:

        public static unsafe godot_packed_byte_array ConvertSystemArrayToNativePackedByteArray(scoped ReadOnlySpan<byte> p_array)
        {
            if (p_array.IsEmpty)
                return new godot_packed_byte_array();
            fixed (byte* src = p_array)
                return NativeFuncs.godotsharp_packed_byte_array_new_mem_copy(src, p_array.Length);
        }

I have confirmed that a valid, non-empty byte is being passed to StoreBuffer(). I do not encounter this issue when running the project from the editor.

Update: this may have something to do with running out of memory? But the file it’s handling is only 118MB.

I was able to get it working by setting the HttpRequest’s DownloadFile to save the zip file directly to disk, and switched to using System.IO’s ZipArchive class to extract it. It seems like some kind of hardcoded memory limit with Godot’s file access classes.