From fa5292bc00f782352db966caa5bdff248c9c9656 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Thu, 2 Jan 2025 02:19:57 +0100 Subject: [PATCH] ChangeSpriteAssociation: Fix OOB reads Fix #3314 --- src/game_interpreter.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index ca65119cec..6aafa6b074 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -2112,8 +2112,17 @@ bool Game_Interpreter::CommandChangeSpriteAssociation(lcf::rpg::EventCommand con } auto file = ToString(CommandStringOrVariableBitfield(com, 3, 1, 4)); - int idx = ValueOrVariableBitfield(com, 3, 2, 1); - bool transparent = com.parameters[2] != 0; + + int idx = 0; + if (com.parameters.size() > 1) { + idx = ValueOrVariableBitfield(com, 3, 2, 1); + } + + bool transparent = false; + if (com.parameters.size() > 2) { + transparent = com.parameters[2] != 0; + } + actor->SetSprite(file, idx, transparent); Main_Data::game_player->ResetGraphic(); return true;