From 92ca220ce1c3346af9ec8ab7e36dc4280dc2c385 Mon Sep 17 00:00:00 2001 From: bhuvan-somisetty Date: Thu, 8 Oct 2026 08:18:08 +0530 Subject: [PATCH] fix(electrum): return error when tip height overflows u32 Validate that the tip height returned from `block_headers_subscribe` fits in `u32` via `u32::try_from` instead of silently truncating with `as u32`. Signed-off-by: bhuvan-somisetty --- crates/electrum/src/bdk_electrum_client.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/electrum/src/bdk_electrum_client.rs b/crates/electrum/src/bdk_electrum_client.rs index a7c94315..98309021 100644 --- a/crates/electrum/src/bdk_electrum_client.rs +++ b/crates/electrum/src/bdk_electrum_client.rs @@ -654,7 +654,8 @@ fn fetch_tip_and_latest_blocks( prev_tip: CheckPoint, ) -> Result<(CheckPoint, BTreeMap), Error> { let HeaderNotification { height, .. } = client.block_headers_subscribe()?; - let new_tip_height = height as u32; + let new_tip_height = u32::try_from(height) + .map_err(|_| Error::Message(format!("server tip height {height} overflows u32")))?; // If electrum returns a tip height that is lower than our previous tip, then checkpoints do // not need updating. We just return the previous tip and use that as the point of agreement. -- 2.49.0