fix(chain): prevent overflow in KeychainTxOutIndex::lookahead_to_target - #2253
Open
CapThunder19 wants to merge 1 commit into
Open
fix(chain): prevent overflow in KeychainTxOutIndex::lookahead_to_target#2253CapThunder19 wants to merge 1 commit into
KeychainTxOutIndex::lookahead_to_target#2253CapThunder19 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
lookahead_to_targetcomputedtarget_index + 1with uncheckedaddition. With
target_index == u32::MAX, this panics in debug buildsand silently no-ops in release builds (wraps to 0, so the lookahead
request is quietly ignored).
Fixed by extracting the delta calculation into a
lookahead_deltahelper using
saturating_addinstead of+, matching the patternalready used elsewhere in this file.
Testing
Added
lookahead_delta_does_not_overflow_at_u32_max, a unit test on thehelper directly. (Not an integration test calling
lookahead_to_targetend-to-end with
u32::MAX, since that would try to derive ~2^31 realkeys on a fresh index.)
cargo test --features miniscript --libcargo test --features miniscript --test test_keychain_txout_indexcargo fmt --check -p bdk_chaincargo clippy -p bdk_chain --features miniscript --lib -- -D warnings#2251