-
-
Notifications
You must be signed in to change notification settings - Fork 572
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
Possible heap corruption issue #842
Comments
It should be quite esay to create a demo project to verify the above idea based on the offical test project and the fact that Steps reproduce to heap corruption issue
diff --git a/test/src/example.cpp b/test/src/example.cpp
index 8375111..7f58e3a 100644
--- a/test/src/example.cpp
+++ b/test/src/example.cpp
@@ -155,6 +155,7 @@ void Example::simple_const_func() const {
String Example::return_something(const String &base) {
UtilityFunctions::print(" Return something called.");
+ auto char_string(base.utf8());
return base;
}
|
Here is upstream You may notice Now Which means, in In any case, I believe GodotCpp has no reason to store anything before the pointer... data structures exploiting that are core types that GodotCpp exposes already, I dont see a reason to exploit such an intrinsic low level detail in the bindings library. The sole fact it's not always present should mean it's not actually necessary. |
I've been running with @lightyears1998 quick fix for a while now, but it doesn't seem like its the right long term solution? We're getting ready to showcase a demo next month and I'd like to feel confident in our release builds if we can. Who would have the expertise here - maybe @vnen? I appreciate all the leg work so far and for the quick fix as well. |
I honestly have no idea. If I wrote this it was quite some time ago and together with a lot of other changes so it's very possible I misunderstood something. It seems @Zylann nailed the cause though, so it seems just a matter of opening the PR to remove the subtraction. |
I am able to confirm the crash with my compiled editor build (TOOLS_ENABLED but not DEBUG_ENABLED using my PR godotengine/godot#73668) with the test extension included in godot-cpp and the test/demo project, and I am able to confirm that the proposed change by @lightyears1998 solves it. @lightyears1998 any chance you could submit your change as a PR? It looks good, and I can confirm it fixes the issue. @Zylann, godot-cpp currently uses the extra 8 bytes so that non-trivially-destructable array types can be properly destructed. This is similar to how the As for why godot-cpp cannot simply pass true for the second argument, it is because As a result, I recommend the fix proposed by lightyears1998. |
If my understanding is correct, the current implementation of
memnew_arr_template
andmemdelete_arr
could lead to heap corruption.godot-cpp/include/godot_cpp/core/memory.hpp
Lines 142 to 146 in be7ed4c
Line 146
*(mem - 1) = p_elements;
assumes that godot-cpp version ofMemory::alloc_static
has allocated extra bytes before actual array, which is not true.Memory::alloc_static
internally callsmem_alloc
from gd extension interface.mem_alloc
function is implemented in godot/core/extension/gdnative_interface.cpp as a call to a macromemalloc(p_size)
, which expands to the godot upstream version ofMemory::alloc_static(m_size)
, and godot upstream version ofMemory::alloc_static
doesn't pre-allocate extras bytes before the actual array.Suggested fix: master...lightyears1998:godot-cpp:fix-heap-corruption
The text was updated successfully, but these errors were encountered: