Repository navigation
[networking] fix reading custom payloads of 0 or 32767 bytes in 11w48a- - #120
Closed
WalkerRodgersArchive wants to merge 1 commit into
Closed
WalkerRodgersArchive wants to merge 1 commit into
WalkerRodgersArchive wants to merge 1 commit into
Conversation
CustomPayloadPacket.read only read the payload when 0 < size < 32767, while the constructor and write allow up to 32767 bytes. A 32767-byte payload was written but not read, desyncing the stream, and a 0-byte payload left data null, so getSize() threw a NullPointerException. Now a negative size throws an IOException and any other size is read in full (an empty array for 0). This change was written by an AI coding assistant (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Hi, thanks for reporting the issue. I will close this PR though, as we do not accept AI-generated code/code changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In 11w48a and older, Networking uses its own
CustomPayloadPacket(in themca0.1.0-mca0.2.1,mca0.2.2-mca0.2.8,mca1.0.16-mca1.2.6andmcb1.0-mc13w39bmodules). Itsreadonly reads the payload when0 < size < Short.MAX_VALUE, while the constructor andwriteaccept payloads of up to and including 32767 bytes. This causes two problems:writesends the size and all 32767 bytes, butreadskips them. The bytes stay in the stream and are parsed as the next packets, so the connection desyncs.readleavesdataasnull.getSize()then throws aNullPointerException, and listeners getnullinstead of an empty array.Fix
readnow throws anIOExceptionfor a negative size and otherwise always readssizebytes (an empty array for 0). The size comes fromreadShort, so it can't be larger thanShort.MAX_VALUEand needs no upper-bound check. The same change is applied to all four copies. 11w49a and newer use the vanilla packet and are not changed.Testing
./gradlew :libraries:networking:buildandbuildfor all six networking version modules, with JDK 21: passes.Round-trip check on the built
mca0.1.0-mca0.2.1jar against the intermediary a0.2.1 server jar: write a payload, append a 4-byte marker, read the packet back, then read the marker. Same check on the published 0.12.1 jar for comparison:datanull,getSize()NPEgetSize()NPEdatanullIOExceptionThe check was a throwaway harness and is not part of this PR (the repo has no test setup).
AI disclosure
The code change and this description were written by an AI coding assistant (Claude Code, using Claude Opus 5.5). A human reviewed the diff before it was submitted.
🤖 Generated with Claude Code