尝试修复泄露到 BundleDelimiterPacket 的解码过程中的意外数据

This commit is contained in:
叁玖领域 2026-06-06 02:41:52 +08:00
parent 349ce41f5f
commit f8185ddb0d
2 changed files with 26 additions and 5 deletions

View File

@ -5,7 +5,7 @@ plugins {
} }
group = "org.adde0109" group = "org.adde0109"
version = "1.4.5" version = "1.4.5-fix1"
repositories { repositories {
mavenCentral() mavenCentral()

View File

@ -26,15 +26,36 @@ public class FML2CRPMResetCompleteDecoder extends ChannelInboundHandlerAdapter {
boolean success = buf.readBoolean(); boolean success = buf.readBoolean();
if (id == 98) { if (id == 98) {
try { try {
IForgeLoginWrapperPacket packet = new GenericForgeLoginWrapperPacket(Unpooled.EMPTY_BUFFER, id, success); // 读取剩余的所有数据
int remainingBytes = buf.readableBytes();
ByteBuf remainingData;
if (remainingBytes > 0) {
// 有剩余数据读取它们
remainingData = Unpooled.buffer(remainingBytes);
remainingData.writeBytes(buf, remainingBytes);
// 调试日志可选可删除
System.out.println("[Ambassador] FML2CRPM packet - id: 98, success: " + success +
", captured " + remainingBytes + " extra bytes");
} else {
// 没有剩余数据使用空缓冲区
remainingData = Unpooled.EMPTY_BUFFER;
}
IForgeLoginWrapperPacket packet = new GenericForgeLoginWrapperPacket(remainingData, id, success);
ctx.fireChannelRead(packet); ctx.fireChannelRead(packet);
} finally { } catch (Exception e) {
buf.release(); // 出错时记录日志
System.err.println("[Ambassador] Error creating FML2CRPM packet: " + e.getMessage());
} }
return; return;
} }
} catch (Exception ignored) {} } catch (Exception ignored) {
// 忽略解析错误回退到正常处理
}
} }
// 恢复读取位置
buf.readerIndex(originalReaderIndex); buf.readerIndex(originalReaderIndex);
} }
ctx.fireChannelRead(msg); ctx.fireChannelRead(msg);