Skip to content

Commit 7725421

Browse files
committed
ChangeActorFace: Fix OOB reads
Fixes an Issue similar to #3320
1 parent ab29d95 commit 7725421

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/game_interpreter.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,17 +2127,26 @@ bool Game_Interpreter::CommandChangeSpriteAssociation(lcf::rpg::EventCommand con
21272127
}
21282128

21292129
bool Game_Interpreter::CommandChangeActorFace(lcf::rpg::EventCommand const& com) { // code 10640
2130-
int id = ValueOrVariableBitfield(com, 2, 0, 0);
2131-
Game_Actor* actor = Main_Data::game_actors->GetActor(id);
2130+
int actor_id = ValueOrVariableBitfield(com, 2, 0, 0);
2131+
Game_Actor* actor = Main_Data::game_actors->GetActor(actor_id);
21322132

21332133
if (!actor) {
2134-
Output::Warning("CommandChangeActorFace: Invalid actor ID {}", id);
2134+
Output::Warning("CommandChangeActorFace: Invalid actor ID {}", actor_id);
21352135
return true;
21362136
}
21372137

2138-
actor->SetFace(
2139-
ToString(CommandStringOrVariableBitfield(com, 2, 1, 3)),
2140-
ValueOrVariableBitfield(com, 2, 2, 1));
2138+
std::string face;
2139+
if (com.parameters.size() > 1) {
2140+
face = ToString(CommandStringOrVariableBitfield(com, 2, 1, 3));
2141+
} else face = ToString(com.string);
2142+
2143+
int face_id;
2144+
if (com.parameters.size() > 2) {
2145+
face_id = ValueOrVariableBitfield(com, 2, 2, 1);
2146+
}
2147+
else face_id = com.parameters[1];
2148+
2149+
actor->SetFace(face, face_id);
21412150
return true;
21422151
}
21432152

0 commit comments

Comments
 (0)