-
-
Notifications
You must be signed in to change notification settings - Fork 332
fix async packet type logic, buffer slicing, and null/out-of-bounds guards #3655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
d2d502b
65ea689
b109988
c98fb95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,14 +134,18 @@ public PacketSendingQueue getSendingQueue(PacketEvent packet) { | |
| * @return The server or client sending queue the packet belongs to. | ||
| */ | ||
| public PacketSendingQueue getSendingQueue(PacketEvent packet, boolean createNew) { | ||
| QueueContainer queues = playerSendingQueues.get(packet.getPlayer()); | ||
| Player player = packet.getPlayer(); | ||
| if (player == null) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not cover the reported login/status failure: those events normally have a non-null |
||
| return null; | ||
|
|
||
| QueueContainer queues = playerSendingQueues.get(player); | ||
|
|
||
| // Safe concurrent initialization | ||
| if (queues == null && createNew) { | ||
| final QueueContainer newContainer = new QueueContainer(); | ||
|
|
||
| // Attempt to map the queue | ||
| queues = playerSendingQueues.putIfAbsent(packet.getPlayer(), newContainer); | ||
| queues = playerSendingQueues.putIfAbsent(player, newContainer); | ||
|
|
||
| if (queues == null) { | ||
| queues = newContainer; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ public T put(int key, T value) { | |
| * @return The old associated value, or NULL. | ||
| */ | ||
| public T remove(int key) { | ||
| if (key < 0 || key >= array.length) return null; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add regression coverage for negative and oversized keys, asserting |
||
| T old = array[key]; | ||
| array[key] = null; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -326,15 +326,9 @@ public void serializeItemStack(DataOutputStream output, ItemStack stack) throws | |
|
|
||
| public byte[] getBytesAndRelease(ByteBuf buf) { | ||
| try { | ||
| if (buf.hasArray()) { | ||
| // heap buffer, we can access the array directly | ||
| return buf.array(); | ||
| } else { | ||
| // direct buffer, we need to copy the bytes into an array | ||
| byte[] bytes = new byte[buf.readableBytes()]; | ||
| buf.readBytes(bytes); | ||
| return bytes; | ||
| } | ||
| byte[] bytes = new byte[buf.readableBytes()]; | ||
| buf.readBytes(bytes); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return bytes; | ||
| } finally { | ||
| ReferenceCountUtil.safeRelease(buf); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mapping correction is right, but no existing test distinguishes the old inverted behavior. Please add a regression test with a sending-only whitelist and assert that its type appears in
getSendingTypes()and notgetReceivingTypes().