]> Untitled Git - bdk/commitdiff
fix(electrum): return error when tip height overflows u32
authorbhuvan-somisetty <somisettybhuvan5@gmail.com>
Thu, 8 Oct 2026 02:48:08 +0000 (08:18 +0530)
committer志宇 <hello@evanlinjin.me>
Sun, 18 Oct 2026 14:12:33 +0000 (01:12 +1100)
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 <somisettybhuvan5@gmail.com>
crates/electrum/src/bdk_electrum_client.rs

index a7c943150a6ac0b1e51ff564aec656c1d9afbb4c..9830902182efd28c13b2c48ee70349faaeeb98ae 100644 (file)
@@ -654,7 +654,8 @@ fn fetch_tip_and_latest_blocks(
     prev_tip: CheckPoint<BlockHash>,
 ) -> Result<(CheckPoint<BlockHash>, BTreeMap<u32, BlockHash>), 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.