Fix FullPacketParser to handle multi-packet chunks #171
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix FullPacketParser to handle multi-packet chunks
Problem
The
FullPacketParserinsrc/serializer.jsonly processes the first packet when a chunk contains multiple packets, resulting in data loss.Current Behavior
When the TCP stream delivers multiple packets in a single chunk:
"Chunk size is X but only Y was read"Example Scenario
This is data loss, not just a warning. The lost packets never reach the application layer.
Why This Happens
TCP provides a byte stream with no packet boundaries. Multiple protocol packets can arrive in a single
chunkfrom the TCP socket. TheSplitter(framing layer) handles varint-length-prefixed packets correctly, butFullPacketParserassumes each chunk contains exactly one packet.Solution
Modified
FullPacketParser._transform()to loop through all packets in a chunk using an offset pointer:After Fix
Impact
Fixed
Unchanged
Testing
Tested with Minecraft protocol 1.21.8 and 1.21.9:
This issue is more prevalent in protocols with high packet rates or when multiple small packets are batched by the TCP stack.
Related
This affects any protocol using
FullPacketParserwhere multiple packets can arrive in a single chunk. The regularParserclass already handles this correctly with buffering - this bringsFullPacketParserto feature parity.