Validate output index (if given) in psbt_parse_rawtx
What changed, and why it matters
This commit adds a safety check in the Ledger Bitcoin app's code that parses raw transactions from PSBT data. Before finalizing, it now verifies that if the caller asked for a specific transaction output by index, that output actually exists. Without this check, the code could have proceeded using data from a non-existent or uninitialized output, potentially leading to incorrect transaction details being shown or signed.
Treat as a security-relevant hardening fix. Review whether the missing check was exploitable to induce signing of unexpected transaction data, and assess if any related PSBT parsing paths have similar index-validation gaps. No immediate incident response is indicated by the diff alone, but the fix should be included in release notes and ideally tested with malformed PSBTs.
Security signals we found
Missing bounds check on attacker-influenced index
Out-of-range array/index access in transaction parsing
PSBT input parsing path reachable during transaction signing
Potential use of uninitialized or incorrect output data in security-critical flow
Evidence from the diff
In call_psbt_parse_rawtx(), after parsing a raw transaction, the function computes the txid and returns output data. The patch adds a bounds check: if output_index is non-negative, it must be strictly less than flow_state.parser_state.n_outputs. Previously, an out-of-range output index could pass through, likely causing the function to read from an invalid or default-initialized outputs entry. This is a defensive fix that prevents use of stale/missing output data during PSBT processing.
Changed components
src/handler/lib/psbt_parse_rawtx.cPSBT raw transaction parsingOutput index validation in transaction signing flowInspect captured patch +5 / −0
diff --git a/src/handler/lib/psbt_parse_rawtx.c b/src/handler/lib/psbt_parse_rawtx.c
index 7380e42..f637746 100644
--- a/src/handler/lib/psbt_parse_rawtx.c
+++ b/src/handler/lib/psbt_parse_rawtx.c
@@ -559,6 +559,11 @@ int call_psbt_parse_rawtx(dispatcher_context_t *dispatcher_context,
return -1;
}
+ // If a specific output was requested, verify it was actually found
+ if (output_index >= 0 && (unsigned int) output_index >= flow_state.parser_state.n_outputs) {
+ return -1;
+ }
+
crypto_hash_digest(&hash_context.header, outputs->txid, 32);
cx_hash_sha256(outputs->txid, 32, outputs->txid, 32);
return 0;
Why this scored 58/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.