Skip to content
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

Empty string in a HashMap results in a crash #85388

Closed
darksylinc opened this issue Nov 26, 2023 · 1 comment · Fixed by #85389
Closed

Empty string in a HashMap results in a crash #85388

darksylinc opened this issue Nov 26, 2023 · 1 comment · Fixed by #85389
Assignees
Milestone

Comments

@darksylinc
Copy link
Contributor

Godot version

4.2.x master [5df9867]

System information

Linux - GCC g++ 9.4.0 - Ubuntu 20.04 LTS

Issue description

I somehow managed to get my Windows system into a broken state were the driver reports 145 extensions, but extension #144 is an empty string.

Therefore Godot will crash while initializing Vulkan and looking for requested device extensions.

Steps to reproduce

Execute the following code:

HashMap<CharString, bool> requested_device_extensions;

CharString extension_name("");
CharString extension_name2("Hello");

requested_device_extensions.insert("HashMap must not be empty", true);

if (requested_device_extensions.has(extension_name2))
	printf("Has Hello\n");
if (requested_device_extensions.has(extension_name))
	printf("Has <empty>\n");

It will crash before . Callstack:

1 hash_djb2                                                                                                                                                   hashfuncs.h        64   0x4a135d6 
2 HashMapHasherDefault::hash                                                                                                                                  hashfuncs.h        313  0x4a1decd 
3 HashMap<CharString, bool, HashMapHasherDefault, HashMapComparatorDefault<CharString>, DefaultTypedAllocator<HashMapElement<CharString, bool>>>::_hash       hash_map.h         85   0x4a1dbd9 
4 HashMap<CharString, bool, HashMapHasherDefault, HashMapComparatorDefault<CharString>, DefaultTypedAllocator<HashMapElement<CharString, bool>>>::_lookup_pos hash_map.h         106  0x4a1d8d7 
5 HashMap<CharString, bool, HashMapHasherDefault, HashMapComparatorDefault<CharString>, DefaultTypedAllocator<HashMapElement<CharString, bool>>>::has         hash_map.h         310  0x4a14788 
6 Main::setup                                                                                                                                                 main.cpp           2115 0x4a088d3 
7 main                                                                                                                                                        godot_linuxbsd.cpp 62   0x497f058 

The reason is that CharString decided to not create a pointer at all to save memory. Hence when hash_djb2 tries to read the first byte, it crashes.

Minimal reproduction project

N / A

@AThousandShips
Copy link
Member

Got a fix for this, will open a PR in a bit

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

Successfully merging a pull request may close this issue.

2 participants