From 4570d46ef6f89a393f7f47a2458034853c3972ca Mon Sep 17 00:00:00 2001 From: Andrei Laiff Date: Tue, 17 Oct 2023 22:04:10 +0300 Subject: [PATCH] Fix packet corruption and log invalid data --- .../network/SPacketLevelTerminalUpdate.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/glodblock/github/network/SPacketLevelTerminalUpdate.java b/src/main/java/com/glodblock/github/network/SPacketLevelTerminalUpdate.java index 91ba91667..5aeecb0c8 100644 --- a/src/main/java/com/glodblock/github/network/SPacketLevelTerminalUpdate.java +++ b/src/main/java/com/glodblock/github/network/SPacketLevelTerminalUpdate.java @@ -49,7 +49,17 @@ public void fromBytes(ByteBuf buf) { int numEntries = buf.readInt(); for (int i = 0; i < numEntries; ++i) { - if (buf.readableBytes() == 0) { + try { + PacketType type = PacketType.values()[buf.readByte()]; + + switch (type) { + case ADD -> this.commands.add(new PacketAdd(buf)); + case REMOVE -> this.commands.add(new PacketRemove(buf)); + case OVERWRITE -> this.commands.add(new PacketOverwrite(buf)); + case RENAME -> this.commands.add(new PacketRename(buf)); + default -> throw new IOException("Unknown packet type received of index " + type); + } + } catch (Exception e) { if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) { AELog.info( "Corrupted packet commands: (" + i @@ -62,19 +72,6 @@ public void fromBytes(ByteBuf buf) { .collect(Collectors.groupingBy(String::new, Collectors.counting()))); AELog.info("Parsed content: -> " + this.commands); } - return; - } - PacketType type = PacketType.values()[buf.readByte()]; - - try { - switch (type) { - case ADD -> this.commands.add(new PacketAdd(buf)); - case REMOVE -> this.commands.add(new PacketRemove(buf)); - case OVERWRITE -> this.commands.add(new PacketOverwrite(buf)); - case RENAME -> this.commands.add(new PacketRename(buf)); - default -> throw new IOException("Unknown packet type received of index " + type); - } - } catch (Exception e) { AELog.debug(e); return; }