Skip to content

Commit 4a8e048

Browse files
committed
Prevent crash when server sends invalid palette
Related: #509
1 parent e7f86f8 commit 4a8e048

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compact_bit_storage/PalettedContainerMixin.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@ private void validateData(FriendlyByteBuf buffer, CallbackInfo ci, int i) {
3030
}
3131
}
3232
if(empty && storArray.length > 0) {
33+
T value;
3334
/* it means the chunk is oversized and wasting memory, take the ID out of the palette and recreate a smaller chunk */
34-
T value = this.data.palette().valueFor(0);
35+
try {
36+
value = this.data.palette().valueFor(0);
37+
} catch (RuntimeException e) {
38+
// Some mods/servers seem to generate buggy palettes. This is not our fault (the game will likely crash later),
39+
// but we catch it here to avoid receiving bug reports for an issue we didn't cause.
40+
return;
41+
}
3542
this.data = this.createOrReuseData(null, 0);
3643
this.data.palette().idFor(value);
3744
}

0 commit comments

Comments
 (0)