From 86e08072e44651634a581e20a689ceaf34e46601 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:14:26 +0200 Subject: [PATCH] streaming: bound ExtraCover's z range too ExtraCover::new checked only x0/x1 against the i32 range, so two areas near i32::MAX or i32::MIN in z built a grid whose row arithmetic (cz + dz) overflows: a panic in debug builds, wrong cells in release. Check z the same way, and test both ends. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/streaming.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/streaming.rs b/crates/horizon-client/src/streaming.rs index 49d1a052b..356614cb3 100644 --- a/crates/horizon-client/src/streaming.rs +++ b/crates/horizon-client/src/streaming.rs @@ -1421,7 +1421,8 @@ impl ExtraCover { (x0, z0, x1, z1) = (x0.min(x - r), z0.min(z - r), x1.max(x + r), z1.max(z + r)); } let (width, depth) = ((x1 - x0 + 1) as u64, (z1 - z0 + 1) as u64); - if width * depth > Self::CELLS || x0 < i64::from(i32::MIN) || x1 > i64::from(i32::MAX) { + let fits = |lo: i64, hi: i64| lo >= i64::from(i32::MIN) && hi <= i64::from(i32::MAX); + if width * depth > Self::CELLS || !fits(x0, x1) || !fits(z0, z1) { return None; } let (x0, z0, width, depth) = (x0 as i32, z0 as i32, width as u32, depth as u32); @@ -2196,6 +2197,8 @@ mod cover_tests { assert!(ExtraCover::new(&[((0, 0), 11), ((100_000, 0), 11)]).is_none()); assert!(ExtraCover::new(&[((0, 0), 11)]).is_none()); assert!(ExtraCover::new(&[((i32::MAX - 1, 0), 11), ((i32::MAX - 3, 0), 11)]).is_none()); + assert!(ExtraCover::new(&[((0, i32::MAX - 1), 11), ((0, i32::MAX - 3), 11)]).is_none()); + assert!(ExtraCover::new(&[((0, i32::MIN + 1), 11), ((0, i32::MIN + 3), 11)]).is_none()); } /// cargo test --release -p horizon-client --lib cover_tests::cover_cost -- --ignored --nocapture