修复内容(FML2CRPMResetCompleteDecoder.java):

对于非 0x02 的数据包:直接释放缓冲区并返回。在重置阶段,唯一需要关注的是 0x02(Login Plugin Response)数据包。其他数据包(如延迟的 PLAY 状态数据包)无法被处于 LOGIN 状态的 MinecraftDecoder 解码,因此安全丢弃。

对于 0x02 + id=98 的数据包:在拦截后添加 buf.release() 来修复内存泄漏。
This commit is contained in:
叁玖领域 2026-06-06 03:31:17 +08:00
parent f8185ddb0d
commit ac891c1ef1
2 changed files with 12 additions and 19 deletions

View File

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

View File

@ -20,42 +20,35 @@ public class FML2CRPMResetCompleteDecoder extends ChannelInboundHandlerAdapter {
int originalReaderIndex = buf.readerIndex();
int packetId = ProtocolUtils.readVarInt(buf);
if (packetId == 0x02 && buf.readableBytes() > 1) {
if (packetId != 0x02) {
buf.release();
return;
}
if (buf.readableBytes() > 1) {
try {
int id = ProtocolUtils.readVarInt(buf);
boolean success = buf.readBoolean();
if (id == 98) {
try {
// 读取剩余的所有数据
int remainingBytes = buf.readableBytes();
ByteBuf remainingData;
if (remainingBytes > 0) {
// 有剩余数据读取它们
remainingData = Unpooled.buffer(remainingBytes);
ByteBuf 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);
} else {
IForgeLoginWrapperPacket packet = new GenericForgeLoginWrapperPacket(Unpooled.EMPTY_BUFFER, id, success);
ctx.fireChannelRead(packet);
}
} catch (Exception e) {
// 出错时记录日志
System.err.println("[Ambassador] Error creating FML2CRPM packet: " + e.getMessage());
}
buf.release();
return;
}
} catch (Exception ignored) {
// 忽略解析错误回退到正常处理
}
}
// 恢复读取位置
buf.readerIndex(originalReaderIndex);
}
ctx.fireChannelRead(msg);