[PR #2816] [MERGED] Protocol: don't panic on malformed chunk sections, compressed frames or legacy pings #4634

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

📋 Pull Request Information

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

Base: main ← Head: fix/malformed-network-input


📝 Commits (1)

  • 2812cf2 Protocol: don't panic on malformed chunk sections, compressed frames or legacy pings

📊 Changes

3 files changed (+43 additions, -5 deletions)

View changed files

📝 crates/horizon-client/src/lan/conn.rs (+1 -1)
📝 crates/horizon-protocol/src/chunk.rs (+23 -1)
📝 crates/horizon-protocol/src/frame.rs (+19 -3)

📄 Description

🤖 Opened by sirrayi's AI agent (Devin), not by sirrayi themselves.

What and why

Three places where malformed network input panicked or was misread:

  1. chunk.rs Paletted::read. A global-palette container takes global_bits.max(wire bits). A server sending 65–255 bits per entry made storage_len divide by zero (64 / bits == 0), and 33–64 bits overflowed shifts later. A malicious server could crash the client with one chunk packet. Vanilla's SimpleBitStorage allows 1–32 bits, so wider containers are now an error. Hosts with mods and wider registries still read; they need far fewer than 32 bits.
  2. frame.rs decompress. The data-length VarInt was assumed to be canonical: frame[1..] for 0, and varint_size(size) otherwise. Vanilla's CompressionDecoder reads it with VarInt.read, so a non-canonical encoding such as 0x80 0x00 for 0 was misread here. Both cases now continue from Reader::position().
  3. lan/conn.rs serve_legacy. If the first read gave no bytes (an interrupted read), data[1] indexed past the end. Now nothing is answered.

Vanilla reference

  • SimpleBitStorage (Validate.inclusiveBetween(1, 32, bits)), PalettedContainer.read.
  • CompressionDecoder.decode.
  • LegacyQueryHandler.

Self-check

  • cargo fmt --all -- --check ✅
  • cargo clippy -p horizon-protocol -p horizon-client --lib --tests -- -D warnings ✅
  • cargo test -p horizon-protocol --lib (102) ✅, cargo test -p horizon-client --lib lan::conn ✅
  • New tests: chunk::tests::wire_bits_wider_than_storage_are_rejected and frame::tests::a_noncanonical_length_prefix_still_reads.

Generated with Devin


🔄 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/2816 **Author:** [@sirrayi](https://github.com/sirrayi) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/28/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/malformed-network-input` --- ### 📝 Commits (1) - [`2812cf2`](https://github.com/horizon-rust/horizon/commit/2812cf201dbc21105266360301ea105c17450387) Protocol: don't panic on malformed chunk sections, compressed frames or legacy pings ### 📊 Changes **3 files changed** (+43 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/lan/conn.rs` (+1 -1) 📝 `crates/horizon-protocol/src/chunk.rs` (+23 -1) 📝 `crates/horizon-protocol/src/frame.rs` (+19 -3) </details> ### 📄 Description > 🤖 Opened by sirrayi's AI agent (Devin), not by sirrayi themselves. ## What and why Three places where malformed network input panicked or was misread: 1. **`chunk.rs` `Paletted::read`.** A global-palette container takes `global_bits.max(wire bits)`. A server sending 65–255 bits per entry made `storage_len` divide by zero (`64 / bits == 0`), and 33–64 bits overflowed shifts later. A malicious server could crash the client with one chunk packet. Vanilla's `SimpleBitStorage` allows 1–32 bits, so wider containers are now an error. Hosts with mods and wider registries still read; they need far fewer than 32 bits. 2. **`frame.rs` `decompress`.** The data-length VarInt was assumed to be canonical: `frame[1..]` for 0, and `varint_size(size)` otherwise. Vanilla's `CompressionDecoder` reads it with `VarInt.read`, so a non-canonical encoding such as `0x80 0x00` for 0 was misread here. Both cases now continue from `Reader::position()`. 3. **`lan/conn.rs` `serve_legacy`.** If the first read gave no bytes (an interrupted read), `data[1]` indexed past the end. Now nothing is answered. ## Vanilla reference - `SimpleBitStorage` (`Validate.inclusiveBetween(1, 32, bits)`), `PalettedContainer.read`. - `CompressionDecoder.decode`. - `LegacyQueryHandler`. ## Self-check - `cargo fmt --all -- --check` ✅ - `cargo clippy -p horizon-protocol -p horizon-client --lib --tests -- -D warnings` ✅ - `cargo test -p horizon-protocol --lib` (102) ✅, `cargo test -p horizon-client --lib lan::conn` ✅ - New tests: `chunk::tests::wire_bits_wider_than_storage_are_rejected` and `frame::tests::a_noncanonical_length_prefix_still_reads`. Generated with [Devin](https://devin.ai) --- <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:48 +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#4634
No description provided.