[PR #2815] [MERGED] Zip: don't trust an entry's declared sizes for allocation #4633

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/2815
Author: @sirrayi
Created: 10/27/2026
Status: ✅ Merged
Merged: 10/28/2026
Merged by: @ludovic111

Base: main ← Head: fix/zip-untrusted-sizes


📝 Commits (1)

  • ce848af Zip: don't trust an entry's declared sizes for allocation

📊 Changes

1 file changed (+68 additions, -6 deletions)

View changed files

📝 crates/horizon-client/src/zip.rs (+68 -6)

📄 Description

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

What and why

zip.rs Zip::read did Vec::with_capacity(entry.compressed_size() as usize) with the size straight from the central directory. A zip64 extra field can claim about 2^63 bytes, and the zip crate (2.4.2) doesn't check sizes against the file. So a malicious server resource pack (or any pack the player opens) aborts the client with a capacity overflow or an allocation failure. That abort can't be caught. The inflate limit size.max(1) * 2 + 1024 could also overflow, and a large declared size let a deflate bomb inflate without bound.

Now:

  • The capacity is capped at the archive's own length.
  • The inflate limit uses saturating arithmetic and is capped at 1 GiB per entry. That is far above any real pack file, and it stops a zip bomb.

Vanilla reference

Horizon-only hardening; vanilla's FilePackResources reads with Java's ZipFile, which streams entries.

Self-check

  • cargo fmt --all -- --check ✅, cargo clippy -p horizon-client --lib --tests -- -D warnings ✅
  • cargo test -p horizon-client --lib zip:: ✅
  • New test zip::tests::declared_sizes_past_the_archive_do_not_abort: a streamed archive whose zip64 extra claims u64::MAX / 2 for both sizes. It panics with a capacity overflow without the fix.

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/2815 **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/zip-untrusted-sizes` --- ### 📝 Commits (1) - [`ce848af`](https://github.com/horizon-rust/horizon/commit/ce848af067abfbc8d00f2bb40a74e4525b1d63bc) Zip: don't trust an entry's declared sizes for allocation ### 📊 Changes **1 file changed** (+68 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/zip.rs` (+68 -6) </details> ### 📄 Description > 🤖 Opened by sirrayi's AI agent (Devin), not by sirrayi themselves. ## What and why `zip.rs` `Zip::read` did `Vec::with_capacity(entry.compressed_size() as usize)` with the size straight from the central directory. A zip64 extra field can claim about 2^63 bytes, and the `zip` crate (2.4.2) doesn't check sizes against the file. So a malicious server resource pack (or any pack the player opens) aborts the client with a capacity overflow or an allocation failure. That abort can't be caught. The inflate limit `size.max(1) * 2 + 1024` could also overflow, and a large declared size let a deflate bomb inflate without bound. Now: - The capacity is capped at the archive's own length. - The inflate limit uses saturating arithmetic and is capped at 1 GiB per entry. That is far above any real pack file, and it stops a zip bomb. ## Vanilla reference Horizon-only hardening; vanilla's `FilePackResources` reads with Java's `ZipFile`, which streams entries. ## Self-check - `cargo fmt --all -- --check` ✅, `cargo clippy -p horizon-client --lib --tests -- -D warnings` ✅ - `cargo test -p horizon-client --lib zip::` ✅ - New test `zip::tests::declared_sizes_past_the_archive_do_not_abort`: a streamed archive whose zip64 extra claims `u64::MAX / 2` for both sizes. It panics with a capacity overflow without the fix. 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#4633
No description provided.