Skip to content

Commit 240407d

Browse files
committed
Fix OutOfBounds exceptions
1 parent f9e0aee commit 240407d

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

core/src/com/hiveworkshop/rms/parsers/mdlx/MdlxLayer.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ public enum FilterMode {
2525
}
2626

2727
public static FilterMode fromId(final int id) {
28-
return values()[id];
28+
if (id > 0 || id < FilterMode.values().length) {
29+
return values()[id];
30+
}
31+
32+
return FilterMode.NONE;
2933
}
3034

3135
public static int nameToId(final String name) {
@@ -80,7 +84,10 @@ public void readMdx(final BinaryReader reader, final int version) {
8084
final int position = reader.position();
8185
final long size = reader.readUInt32();
8286

83-
this.filterMode = FilterMode.fromId(reader.readInt32());
87+
final int filterModeIndex = reader.readInt32();
88+
if (filterModeIndex > 0 && filterModeIndex < FilterMode.values().length) {
89+
this.filterMode = FilterMode.fromId(filterModeIndex);
90+
}
8491
this.flags = reader.readInt32(); // UInt32 in JS
8592
this.textureId = reader.readInt32();
8693
this.textureAnimationId = reader.readInt32();

0 commit comments

Comments
 (0)