godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.15k stars 21.19k forks source link

Executing `AudioStreamPlaybackInteractive.switch_to_clip_by_name` function crashes Godot #90474

Closed qarmin closed 4 months ago

qarmin commented 7 months ago

Tested versions

4.3.dev.custom_build 6c579280630715ff7da8310d405ef34194847294

System information

Ubuntu 22.04 CI

Issue description

When executing (this code was automatically minimized, so it is possible, that an even more "minimal" project can be created)

extends Node
func _process(delta):
    var temp_variable37 = ArrayMesh.new()
    temp_variable37.surface_find_by_name("")
    temp_variable37.surface_get_name(29)
    temp_variable37.get_shadow_mesh()
    temp_variable37.get_custom_aabb()
    var temp_variable79 = AudioStreamPlaybackInteractive.new()
    temp_variable79.switch_to_clip_by_name(StringName("."))

Godot crashes:

Godot Engine v4.3.dev.custom_build - https://godotengine.org

ERROR: Index p_idx = 29 is out of bounds (surfaces.size() = 0).
   at: surface_get_name (scene/resources/mesh.cpp:1958)
modules/interactive_music/audio_stream_interactive.cpp:979:44: runtime error: member call on null pointer of type 'struct AudioStreamInteractive'
modules/interactive_music/audio_stream_interactive.cpp:979:44: runtime error: member access within null pointer of type 'struct AudioStreamInteractive'
================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.3.dev.custom_build
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] ./godot.linuxbsd.editor.dev.x86_64.san(+0x3fda69d3) [0x55d2f11c29d3] (/home/runner/work/Qarminer/Qarminer/godot/platform/linuxbsd/crash_handler_linuxbsd.cpp:61)
[2] /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f0f6ae42520] (??:0)
[3] AudioStreamPlaybackInteractive::switch_to_clip_by_name(StringName const&) (/home/runner/work/Qarminer/Qarminer/godot/modules/interactive_music/audio_stream_interactive.cpp:979 (discriminator 1))
[4] void call_with_variant_args_helper<__UnexistingClass, StringName const&, 0ul>(__UnexistingClass*, void (__UnexistingClass::*)(StringName const&), Variant const**, Callable::CallError&, IndexSequence<0ul>) (/home/runner/work/Qarminer/Qarminer/godot/./core/variant/binder_common.h:304 (discriminator 4))
[5] void call_with_variant_args_dv<__UnexistingClass, StringName const&>(__UnexistingClass*, void (__UnexistingClass::*)(StringName const&), Variant const**, int, Callable::CallError&, Vector<Variant> const&) (/home/runner/work/Qarminer/Qarminer/godot/./core/variant/binder_common.h:422)
[6] MethodBindT<StringName const&>::call(Object*, Variant const**, int, Callable::CallError&) const (/home/runner/work/Qarminer/Qarminer/godot/./core/object/method_bind.h:344)
[7] Object::callp(StringName const&, Variant const**, int, Callable::CallError&) (/home/runner/work/Qarminer/Qarminer/godot/core/object/object.cpp:837)
[8] Variant::callp(StringName const&, Variant const**, int, Variant&, Callable::CallError&) (/home/runner/work/Qarminer/Qarminer/godot/core/variant/variant_call.cpp:1212)
[9] GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Callable::CallError&, GDScriptFunction::CallState*) (/home/runner/work/Qarminer/Qarminer/godot/modules/gdscript/gdscript_vm.cpp:1735)
[10] GDScriptInstance::callp(StringName const&, Variant const**, int, Callable::CallError&) (/home/runner/work/Qarminer/Qarminer/godot/modules/gdscript/gdscript.cpp:1970)
[11] bool Node::_gdvirtual__process_call<false>(double) (/home/runner/work/Qarminer/Qarminer/godot/scene/main/node.h:355 (discriminator 1))
[12] Node::_notification(int) (/home/runner/work/Qarminer/Qarminer/godot/scene/main/node.cpp:59)
[13] Node::_notificationv(int, bool) (/home/runner/work/Qarminer/Qarminer/godot/./scene/main/node.h:49 (discriminator 14))
[14] Object::notification(int, bool) (/home/runner/work/Qarminer/Qarminer/godot/core/object/object.cpp:902)
[15] SceneTree::_process_group(SceneTree::ProcessGroup*, bool) (/home/runner/work/Qarminer/Qarminer/godot/scene/main/scene_tree.cpp:979)
[16] SceneTree::_process(bool) (/home/runner/work/Qarminer/Qarminer/godot/scene/main/scene_tree.cpp:1051 (discriminator 2))
[17] SceneTree::process(double) (/home/runner/work/Qarminer/Qarminer/godot/scene/main/scene_tree.cpp:536)
[18] Main::iteration() (/home/runner/work/Qarminer/Qarminer/godot/main/main.cpp:4016)
[19] OS_LinuxBSD::run() (/home/runner/work/Qarminer/Qarminer/godot/platform/linuxbsd/os_linuxbsd.cpp:962)
[20] ./godot.linuxbsd.editor.dev.x86_64.san(main+0x4bb) [0x55d2f11c2374] (/home/runner/work/Qarminer/Qarminer/godot/platform/linuxbsd/godot_linuxbsd.cpp:85)
[21] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f0f6ae29d90] (??:0)
[22] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f0f6ae29e40] (??:0)
[23] ./godot.linuxbsd.editor.dev.x86_64.san(_start+0x25) [0x55d2f11c1df5] (??:?)
-- END OF BACKTRACE --
================================================================
Aborted (core dumped)

This example was found by Godot fuzzer - Qarminer, so it is quite unlikelly that this code could be used in real project, but still this should be handled gracefully.

Memory leaks or asan backtraces are visible when using Godot build with sanitizers support - https://github.com/qarmin/GodotBuilds/actions (linux -> linux-editor-sanitizers)

Steps to reproduce

Above

Minimal reproduction project (MRP)

Above

AThousandShips commented 7 months ago

Happens due to missing checks, will write a fix