Repository: godotengine/godot (language: cpp)

Issue:
Editor crashes with signal 11 when exporting a project and trying to include a 2 GiB file in the `.pck` file
### Tested versions

- Reproducible in: 4.3.stable, 4.4.1.stable.
- Not reproducible in: 4.2.2.stable

### System information

Godot v4.4.1.stable (49a5bc7b6) - cpe:/o:nixos:nixos:24.11 #1-NixOS SMP PREEMPT_DYNAMIC Sat Mar 22 19:56:59 UTC 2025 on Wayland - X11 display driver, Multi-window, 1 monitor - OpenGL 3 (Compatibility) - AMD Radeon RX 580 Series (radeonsi, polaris10, LLVM 18.1.8, DRM 3.61, 6.13.8) - AMD Ryzen 5 3600 6-Core Processor (12 threads)

### Issue description

If I tell the Godot editor to include a large file (2 GiB) in a project’s `.pck` file, then when I try to export that project, the Godot editor crashes with this error:

<pre><samp>Godot Engine v4.4.1.stable.nixpkgs.49a5bc7b6 - https://godotengine.org
Inconsistent value (1) for DRI_PRIME. Should be &lt; 1 (GPU devices count). Using: 0
OpenGL API 4.6 (Core Profile) Mesa 24.2.8 - Compatibility - Using Device: AMD - AMD Radeon RX 580 Series (radeonsi, polaris10, LLVM 18.1.8, DRM 3.61, 6.13.8)

first_scan_filesystem: begin: Project initialization steps: 5
        first_scan_filesystem: step 0: Scanning file structure...
        first_scan_filesystem: step 1: Loading global class names...
        first_scan_filesystem: step 2: Verifying GDExtensions...
        first_scan_filesystem: step 3: Creating autoload scripts...
        first_scan_filesystem: step 4: Initializing plugins...
        first_scan_filesystem: step 5: Starting file scan...
first_scan_filesystem: end
savepack: begin: Packing steps: 102
        savepack: step 2: Storing File: res://.godot/imported/icon.webp-e94f9a68b0f625a567a797079e4d325f.ctex
        savepack: step 2: Storing File: res://icon.webp.import
        savepack: step 35: Storing File: res://.godot/exported/133200997/export-3070c538c03ee49b7677ff960a3f5195-main.scn

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.4.1.stable.nixpkgs (49a5bc7b616bd04689a2c89e89bda41f50241464)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /nix/store/rmy663w9p7xb202rcln4jjzmvivznmz8-glibc-2.40-66/lib/libc.so.6(+0x40f30) [0x7ffff7c40f30] (??:0)
[2] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x50bf7d3] (??:?)
[3] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x11cc37f] (??:?)
[4] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x11cc55c] (??:?)
[5] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x1c9b4b8] (??:?)
[6] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x1ca31de] (??:?)
[7] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x1ca5a78] (??:?)
[8] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x1ca92b4] (??:?)
[9] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x195c68b] (??:?)
[10] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x4967fd3] (??:?)
[11] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x82a8d3] (??:?)
[12] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x185e0b2] (??:?)
[13] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x48def98] (??:?)
[14] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x2a21de7] (??:?)
[15] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x2a515c2] (??:?)
[16] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x2a9c429] (??:?)
[17] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x51c606] (??:?)
[18] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x4242e2] (??:?)
[19] /nix/store/rmy663w9p7xb202rcln4jjzmvivznmz8-glibc-2.40-66/lib/libc.so.6(+0x2a1fe) [0x7ffff7c2a1fe] (??:0)
[20] /nix/store/rmy663w9p7xb202rcln4jjzmvivznmz8-glibc-2.40-66/lib/libc.so.6(__libc_start_main+0x89) [0x7ffff7c2a2b9] (??:0)
[21] /nix/store/mb8wrl1pf82z8lkg72qqpnjqiy5bbzgn-godot4-4.4.1-stable/bin/godot4() [0x4485b5] (??:?)
-- END OF BACKTRACE --
================================================================
Aborted (core dumped)
</samp></pre>

### Steps to reproduce

Follow the instructions in [the repo that I created for this bug’s minimum reproduction project](https://codeberg.org/JasonYundt/godot-export-crash-reproduction-project).

### Minimal reproduction project (MRP)

<https://codeberg.org/JasonYundt/godot-export-crash-reproduction-project>


Discussion / hints:
I can reproduce the issue with the MRP.

Backtrace with debug symbols:
```
================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.5.dev.custom_build (1f56d96cf2c768c3844c68ccb504dfeee841ae15)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /lib64/libc.so.6(+0x1a050) [0x7f4bab1bc050] (??:0)
[2] /home/akien/.local/bin/godot-git(mbedtls_internal_md5_process+0xc4) [0x843da99] (/home/akien/Godot/godot/thirdparty/mbedtls/library/alignment.h:177)
[3] /home/akien/.local/bin/godot-git(mbedtls_md5_update+0x10e) [0x843f1d3] (/home/akien/Godot/godot/thirdparty/mbedtls/library/md5.c:237)
[4] /home/akien/.local/bin/godot-git(mbedtls_md5+0x53) [0x843f466] (/home/akien/Godot/godot/thirdparty/mbedtls/library/md5.c:330)
[5] CryptoCore::md5(unsigned char const*, int, unsigned char*) (/home/akien/Godot/godot/core/crypto/crypto_core.cpp:239)
[6] EditorExportPlatform::_save_pack_file(void*, String const&, Vector<unsigned char> const&, int, int, Vector<String> const&, Vector<String> const&, Vector<unsigned char> const&, unsigned long) (/home/akien/Godot/godot/editor/export/editor_export_platform.cpp:330)
[7] EditorExportSaveProxy::save_file(void*, String const&, Vector<unsigned char> const&, int, int, Vector<String> const&, Vector<String> const&, Vector<unsigned char> const&, unsigned long) (/home/akien/Godot/godot/editor/export/editor_export_platform.cpp:68)
[8] EditorExportPlatform::export_project_files(Ref<EditorExportPreset> const&, bool, Error (*)(void*, String const&, Vector<unsigned char> const&, int, int, Vector<String> const&, Vector<String> const&, Vector<unsigned char> const&, unsigned long), Error (*)(void*, String const&), void*, Error (*)(void*, SharedObject const&)) (/home/akien/Godot/godot/editor/export/editor_export_platform.cpp:1495)
[9] EditorExportPlatform::save_pack(Ref<EditorExportPreset> const&, bool, String const&, Vector<SharedObject>*, Error (*)(void*, String const&, Vector<unsigned char> const&, int, int, Vector<String> const&, Vector<String> const&, Vector<unsigned char> const&, unsigned long), Error (*)(void*, String const&), bool, long*, long*) (/home/akien/Godot/godot/editor/export/editor_export_platform.cpp:1908)
[10] EditorExportPlatform::export_pack(Ref<EditorExportPreset> const&, bool, String const&, BitField<EditorExportPlatform::DebugFlags>) (/home/akien/Godot/godot/editor/export/editor_export_platform.cpp:2197)
[11] EditorNode::_fs_changed() (/home/akien/Godot/godot/editor/editor_node.cpp:1141)
[12] void call_with_variant_args_helper<EditorNode>(EditorNode*, void (EditorNode::*)(), Variant const**, Callable::CallError&, IndexSequence<>) (/home/akien/Godot/godot/core/variant/binder_common.h:319)
[13] void call_with_variant_args<EditorNode>(EditorNode*, void (EditorNode::*)(), Variant const**, int, Callable::CallError&) (/home/akien/Godot/godot/core/variant/binder_common.h:429)
[14] CallableCustomMethodPointer<EditorNode, void>::call(Variant const**, int, Variant&, Callable::CallError&) const (/home/akien/Godot/godot/core/object/callable_method_pointer.h:108)
[15] Callable::callp(Variant const**, int, Variant&, Callable::CallError&) const (/home/akien/Godot/godot/core/variant/callable.cpp:57)
[16] Object::emit_signalp(StringName const&, Variant const**, int) (/home/akien/Godot/godot/core/object/object.cpp:1258)
[17] Node::emit_signalp(StringName const&, Variant const**, int) (/home/akien/Godot/godot/scene/main/node.cpp:4014)
[18] Error Object::emit_signal<>(StringName const&) (/home/akien/Godot/godot/core/object/object.h:955)
[19] EditorFileSystem::_notification(int) (/home/akien/Godot/godot/editor/editor_file_system.cpp:1778)
[20] EditorFileSystem::_notification_forwardv(int) (/home/akien/Godot/godot/editor/editor_file_system.h:148)
[21] Object::_notification_forward(int) (/home/akien/Godot/godot/core/object/object.cpp:919)
[22] Object::notification(int, bool) (/home/akien/Godot/godot/core/object/object.h:906)
[23] SceneTree::_process_group(SceneTree::ProcessGroup*, bool) (/home/akien/Godot/godot/scene/main/scene_tree.cpp:1076)
[24] SceneTree::_process(bool) (/home/akien/Godot/godot/scene/main/scene_tree.cpp:1148 (discriminator 2))
[25] SceneTree::process(double) (/home/akien/Godot/godot/scene/main/scene_tree.cpp:594)
[26] Main::iteration() (/home/akien/Godot/godot/main/main.cpp:4689 (discriminator 3))
[27] OS_LinuxBSD::run() (/home/akien/Godot/godot/platform/linuxbsd/os_linuxbsd.cpp:980 (discriminator 1))
[28] /home/akien/.local/bin/godot-git(main+0x14b) [0x6c40ef1] (/home/akien/Godot/godot/platform/linuxbsd/godot_linuxbsd.cpp:85)
[29] /lib64/libc.so.6(+0x3248) [0x7f4bab1a5248] (??:0)
[30] /lib64/libc.so.6(__libc_start_main+0x8b) [0x7f4bab1a530b] (??:0)
[31] /home/akien/.local/bin/godot-git(_start+0x25) [0x6c40ce5] (??:?)
-- END OF BACKTRACE --
================================================================
```

Seems to crash when computing the file's MD5 sum.
CryptoCore seems to be using `int` for buffer sizes, should likely be changed to `uint64_t` (or `size_t` like mbedtls uses).

Fix patch:
diff --git a/core/crypto/crypto_core.cpp b/core/crypto/crypto_core.cpp
index 13852d517794..9d2c346e3ae1 100644
--- a/core/crypto/crypto_core.cpp
+++ b/core/crypto/crypto_core.cpp
@@ -214,8 +214,8 @@ Error CryptoCore::AESContext::decrypt_cfb(size_t p_length, uint8_t p_iv[16], con
 }
 
 // CryptoCore
-String CryptoCore::b64_encode_str(const uint8_t *p_src, int p_src_len) {
-	int b64len = p_src_len / 3 * 4 + 4 + 1;
+String CryptoCore::b64_encode_str(const uint8_t *p_src, size_t p_src_len) {
+	size_t b64len = p_src_len / 3 * 4 + 4 + 1;
 	Vector<uint8_t> b64buff;
 	b64buff.resize(b64len);
 	uint8_t *w64 = b64buff.ptrw();
@@ -225,27 +225,27 @@ String CryptoCore::b64_encode_str(const uint8_t *p_src, int p_src_len) {
 	return ret ? String() : (const char *)&w64[0];
 }
 
-Error CryptoCore::b64_encode(uint8_t *r_dst, int p_dst_len, size_t *r_len, const uint8_t *p_src, int p_src_len) {
+Error CryptoCore::b64_encode(uint8_t *r_dst, size_t p_dst_len, size_t *r_len, const uint8_t *p_src, size_t p_src_len) {
 	int ret = mbedtls_base64_encode(r_dst, p_dst_len, r_len, p_src, p_src_len);
 	return ret ? FAILED : OK;
 }
 
-Error CryptoCore::b64_decode(uint8_t *r_dst, int p_dst_len, size_t *r_len, const uint8_t *p_src, int p_src_len) {
+Error CryptoCore::b64_decode(uint8_t *r_dst, size_t p_dst_len, size_t *r_len, const uint8_t *p_src, size_t p_src_len) {
 	int ret = mbedtls_base64_decode(r_dst, p_dst_len, r_len, p_src, p_src_len);
 	return ret ? FAILED : OK;
 }
 
-Error CryptoCore::md5(const uint8_t *p_src, int p_src_len, unsigned char r_hash[16]) {
+Error CryptoCore::md5(const uint8_t *p_src, size_t p_src_len, unsigned char r_hash[16]) {
 	int ret = mbedtls_md5_ret(p_src, p_src_len, r_hash);
 	return ret ? FAILED : OK;
 }
 
-Error CryptoCore::sha1(const uint8_t *p_src, int p_src_len, unsigned char r_hash[20]) {
+Error CryptoCore::sha1(const uint8_t *p_src, size_t p_src_len, unsigned char r_hash[20]) {
 	int ret = mbedtls_sha1_ret(p_src, p_src_len, r_hash);
 	return ret ? FAILED : OK;
 }
 
-Error CryptoCore::sha256(const uint8_t *p_src, int p_src_len, unsigned char r_hash[32]) {
+Error CryptoCore::sha256(const uint8_t *p_src, size_t p_src_len, unsigned char r_hash[32]) {
 	int ret = mbedtls_sha256_ret(p_src, p_src_len, r_hash, 0);
 	return ret ? FAILED : OK;
 }
diff --git a/core/crypto/crypto_core.h b/core/crypto/crypto_core.h
index 75455eb9ddad..8ef50fbcf7db 100644
--- a/core/crypto/crypto_core.h
+++ b/core/crypto/crypto_core.h
@@ -106,11 +106,11 @@ class CryptoCore {
 		Error decrypt_cfb(size_t p_length, uint8_t p_iv[16], const uint8_t *p_src, uint8_t *r_dst);
 	};
 
-	static String b64_encode_str(const uint8_t *p_src, int p_src_len);
-	static Error b64_encode(uint8_t *r_dst, int p_dst_len, size_t *r_len, const uint8_t *p_src, int p_src_len);
-	static Error b64_decode(uint8_t *r_dst, int p_dst_len, size_t *r_len, const uint8_t *p_src, int p_src_len);
+	static String b64_encode_str(const uint8_t *p_src, size_t p_src_len);
+	static Error b64_encode(uint8_t *r_dst, size_t p_dst_len, size_t *r_len, const uint8_t *p_src, size_t p_src_len);
+	static Error b64_decode(uint8_t *r_dst, size_t p_dst_len, size_t *r_len, const uint8_t *p_src, size_t p_src_len);
 
-	static Error md5(const uint8_t *p_src, int p_src_len, unsigned char r_hash[16]);
-	static Error sha1(const uint8_t *p_src, int p_src_len, unsigned char r_hash[20]);
-	static Error sha256(const uint8_t *p_src, int p_src_len, unsigned char r_hash[32]);
+	static Error md5(const uint8_t *p_src, size_t p_src_len, unsigned char r_hash[16]);
+	static Error sha1(const uint8_t *p_src, size_t p_src_len, unsigned char r_hash[20]);
+	static Error sha256(const uint8_t *p_src, size_t p_src_len, unsigned char r_hash[32]);
 };


Test patch: