Merge pull request #713 from Foundation-Devices/SFT-7485-update-foundation-ur
What changed, and why it matters
This commit updates a Rust dependency called foundation-ur from version 0.4 to 0.5 and adds a test showing that a malformed QR code fragment no longer corrupts the next valid scan. The change appears to fix a state-poisoning bug in the QR code decoder used by the Passport hardware wallet, but the actual fix is inside the external library, not visible in this diff.
Review the foundation-ur 0.5.0 changelog and upstream diff to confirm the exact bug fixed, and verify that the Passport firmware's decoder integration now rejects malformed fragments cleanly. Consider adding further fuzz or boundary tests for sequence_count, checksum, and message_length mismatches.
Security signals we found
Dependency update to a newer crate version
Regression test for decoder state poisoning after malformed input
QR/UR code decoder is an attack surface for untrusted scanned data
Potential denial-of-service or incorrect decoding from a single malicious scan
Evidence from the diff
The commit bumps the foundation-ur crate from 0.4.0 to 0.5.0 in Cargo.lock and Cargo.toml, and adds a regression test in extmod/foundation-rust/src/ur/decoder.rs. The test, named rejected_metadata_does_not_poison_next_scan, crafts a multipart UR fragment with inconsistent metadata (sequence_count tampered from 2 to 1), feeds it to ur_decoder_receive, and verifies that the decoder remains empty and that a subsequent legitimate two-part crypto-psbt message can still be decoded correctly. This implies that in foundation-ur 0.4, a rejected or malformed fragment could leave stale state in the decoder, causing later valid fragments to fail or decode incorrectly. The actual code change that prevents the poisoning is not shown in this repository diff because it lives in the upstream foundation-ur crate.
Changed components
extmod/foundation-rust/Cargo.lockextmod/foundation-rust/Cargo.tomlextmod/foundation-rust/src/ur/decoder.rsfoundation-ur crate (upstream dependency)Inspect captured patch +69 / −3
### extmod/foundation-rust/Cargo.lock
@@ -145,9 +145,9 @@ dependencies = [
[[package]]
name = "foundation-ur"
-version = "0.4.0"
+version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "de4d0b63162220b26a3a955478ebc02e51fe77aa38181d058c55f3d1d6664428"
+checksum = "6f61a07868d631ad2b32bef710f3d4e4ed9787bd760d87db4aca04f6fdd330a8"
dependencies = [
"bitcoin_hashes",
"crc",
### extmod/foundation-rust/Cargo.toml
@@ -33,7 +33,7 @@ version = "0.3"
default-features = false
[dependencies.foundation-ur]
-version = "0.4"
+version = "0.5"
default-features = false
[dependencies.foundation-urtypes]
### extmod/foundation-rust/src/ur/decoder.rs
@@ -281,3 +281,69 @@ pub unsafe extern "C" fn ur_decode_single_part(
true
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use foundation_ur::fountain::part::Part;
+
+ #[test]
+ fn rejected_metadata_does_not_poison_next_scan() {
+ let mut decoder = UR_Decoder {
+ inner: HeaplessDecoder::new(),
+ };
+ let fragment = Part {
+ sequence: 1,
+ sequence_count: 2,
+ message_length: 2,
+ checksum: 0,
+ data: &[1],
+ };
+ let serialized = UR::MultiPartDeserialized {
+ ur_type: "bytes",
+ fragment: fragment.clone(),
+ }
+ .to_string()
+ .replacen("1-2", "1-1", 1);
+ let mut error = UR_Error {
+ kind: super::super::UR_ErrorKind::UR_ERROR_KIND_OTHER,
+ message: core::ptr::null(),
+ len: 0,
+ };
+ let mut frames = 0;
+ // SAFETY: Test the FFI with a live string; no other test writes UR_ERROR.
+ assert!(!unsafe {
+ ur_decoder_receive(
+ &mut decoder,
+ serialized.as_ptr(),
+ serialized.len(),
+ &mut error,
+ &mut frames,
+ )
+ });
+ assert!(decoder.inner.is_empty());
+ assert_eq!(decoder.inner.ur_type(), None);
+ for sequence in 1..=2 {
+ let serialized = UR::MultiPartDeserialized {
+ ur_type: "crypto-psbt",
+ fragment: Part {
+ sequence,
+ ..fragment.clone()
+ },
+ }
+ .to_string();
+ // SAFETY: Test the FFI with a live string; no other test writes UR_ERROR.
+ assert!(unsafe {
+ ur_decoder_receive(
+ &mut decoder,
+ serialized.as_ptr(),
+ serialized.len(),
+ &mut error,
+ &mut frames,
+ )
+ });
+ }
+ assert!(decoder.inner.is_complete());
+ assert_eq!(decoder.inner.message().unwrap(), Some(&[1, 1][..]));
+ }
+}Why this scored 49/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.