[PR #2833] [MERGED] net: skip a compressed frame that carries no packet #4643

Closed
opened 2026-11-03 05:06:52 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2833
Author: @levzzz5154
Created: 10/27/2026
Status: ✅ Merged
Merged: 10/28/2026
Merged by: @ludovic111

Base: main ← Head: fix/empty-compressed-packet


📝 Commits (1)

  • 65bca4c net: skip a compressed frame that carries no packet

📊 Changes

2 files changed (+38 additions, -0 deletions)

View changed files

📝 crates/horizon-protocol/src/connection.rs (+33 -0)
📝 crates/horizon-protocol/src/frame.rs (+5 -0)

📄 Description

🤖 Opened by levzzz5154's AI agent (Claude Code), not by levzzz5154 himself.

What and why

A client that joined a server which sends a compressed frame with an
empty payload was disconnected with needed 1 bytes, 0 left.

The frame is valid: the compression format's uncompressed-length field
is 0, which means the rest of the frame is the packet body, and here
that body is empty. Vanilla accepts it — the frame is handed to the
packet decoder, which reads no packet from an empty buffer, so the frame
carries no packet and the connection stays up.

Horizon read the packet id from the empty body instead, and the missing
byte ended the connection. ConnReader::recv now skips a frame with no
packet in it, the way vanilla's pipeline does.

A frame with no bytes at all (a zero length prefix) is a corrupted frame
in vanilla, so the frame splitter now says that (Frame length cannot be zero) rather than failing later with a missing byte.

Fixes #2739

Vanilla reference

  • net.minecraft.network.CompressionDecoder.decode —
    int uncompressedLength = VarInt.read(in); if (uncompressedLength == 0) { out.add(in.readBytes(in.readableBytes())); }:
    an uncompressed length of 0 means the rest of the frame is the packet
    body, and that body may be empty.
  • net.minecraft.network.Varint21FrameDecoder.decode —
    if (length == 0) { throw new CorruptedFrameException("Frame length cannot be zero"); }:
    a frame with no bytes is a corrupted frame, not an empty packet.
  • net.minecraft.network.PacketDecoder.decode — the packet decoder is a
    Netty ByteToMessageDecoder, which only decodes while its buffer is
    readable: an empty frame produces no packet, and the connection stays
    up.

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main with the stable toolchain, on cachyos-x8664, against upstream/main at 6f4b1bf4c, 2 min 53 s)

Check Result
Scope ✅ 2 files, +38 −0
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 336 passed (17 s)
rustfmt ✅ (5 s)
clippy ✅ (1 min 53 s)
tests: horizon-protocol ✅ 101 passed (23 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 39 affected, to run in CI (--quick): block_entity_render, block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, ghost_recipe, hardcore_respawn and 27 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The focused check for the change, an_empty_compressed_frame_is_skipped,
sends the empty compressed frame (the length prefix, then the
uncompressed length 0 and nothing else) followed by a real packet, and
reads the real packet:

let (id, payload) = c.recv().unwrap();
assert_eq!((id, payload.as_slice()), (3, &b"after"[..]));

With the fix reverted (the skip removed) the same test fails with the
error the issue reports:

test connection::tests::an_empty_compressed_frame_is_skipped ... FAILED
panicked at crates/horizon-protocol/src/connection.rs:528:38:
called `Result::unwrap()` on an `Err` value: Error("needed 1 bytes, 0 left")
test result: FAILED. 0 passed; 1 failed

cargo test -p horizon-protocol is green (101 passed) and
cargo fmt -p horizon-protocol is clean.

🤖 Generated with Claude Code.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/2833 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/28/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/empty-compressed-packet` --- ### 📝 Commits (1) - [`65bca4c`](https://github.com/horizon-rust/horizon/commit/65bca4ce9874c1ce93914a1aca27dedd9b26183f) net: skip a compressed frame that carries no packet ### 📊 Changes **2 files changed** (+38 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-protocol/src/connection.rs` (+33 -0) 📝 `crates/horizon-protocol/src/frame.rs` (+5 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code), not by levzzz5154 himself. ## What and why A client that joined a server which sends a compressed frame with an empty payload was disconnected with `needed 1 bytes, 0 left`. The frame is valid: the compression format's uncompressed-length field is 0, which means the rest of the frame is the packet body, and here that body is empty. Vanilla accepts it — the frame is handed to the packet decoder, which reads no packet from an empty buffer, so the frame carries no packet and the connection stays up. Horizon read the packet id from the empty body instead, and the missing byte ended the connection. `ConnReader::recv` now skips a frame with no packet in it, the way vanilla's pipeline does. A frame with no bytes at all (a zero length prefix) is a corrupted frame in vanilla, so the frame splitter now says that (`Frame length cannot be zero`) rather than failing later with a missing byte. Fixes #2739 ## Vanilla reference - `net.minecraft.network.CompressionDecoder.decode` — `int uncompressedLength = VarInt.read(in); if (uncompressedLength == 0) { out.add(in.readBytes(in.readableBytes())); }`: an uncompressed length of 0 means the rest of the frame is the packet body, and that body may be empty. - `net.minecraft.network.Varint21FrameDecoder.decode` — `if (length == 0) { throw new CorruptedFrameException("Frame length cannot be zero"); }`: a frame with no bytes is a corrupted frame, not an empty packet. - `net.minecraft.network.PacketDecoder.decode` — the packet decoder is a Netty `ByteToMessageDecoder`, which only decodes while its buffer is readable: an empty frame produces no packet, and the connection stays up. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` with the `stable` toolchain, on cachyos-x8664, against upstream/main at 6f4b1bf4c, 2 min 53 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +38 −0 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 336 passed (17 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (1 min 53 s) | | tests: horizon-protocol | ✅ 101 passed (23 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 39 affected, to run in CI (--quick): block_entity_render, block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, ghost_recipe, hardcore_respawn and 27 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The focused check for the change, `an_empty_compressed_frame_is_skipped`, sends the empty compressed frame (the length prefix, then the uncompressed length 0 and nothing else) followed by a real packet, and reads the real packet: ```rust let (id, payload) = c.recv().unwrap(); assert_eq!((id, payload.as_slice()), (3, &b"after"[..])); ``` With the fix reverted (the skip removed) the same test fails with the error the issue reports: ``` test connection::tests::an_empty_compressed_frame_is_skipped ... FAILED panicked at crates/horizon-protocol/src/connection.rs:528:38: called `Result::unwrap()` on an `Err` value: Error("needed 1 bytes, 0 left") test result: FAILED. 0 passed; 1 failed ``` `cargo test -p horizon-protocol` is green (101 passed) and `cargo fmt -p horizon-protocol` is clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:06:52 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#4643
No description provided.