Repository navigation
Description
I encountered a bitcoin-uri fuzzing crash that could just be expected behavior within the spec that just is a little weird.
Parsing this uri Bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX6=q3Ҁf&pj=\u{3}\0\0\0\0\0\0http\r\r\r\r\r\r\r\r\r:\r\r\\.onion\\\\\\\\\\q3 and then re-serializing it in a roundtrip results in a loss of data. Resulting uri bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?pj=HTTP://.ONION/////q3 my question is whether it is expected that uris may not always be able to be de-serialized in a roundtrip and end up the same, especially when considering unknown or unsupported data.
It is my intuition that a uri should retain the unknown data so that it is not lost just because payjoin does not understand how to parse it but maybe it is just expected that an external uri should be cloned or passed as a ref into parsing programs.
Here is a basic unittest to show how this happens.
#[test]
fn test_fuzz_crash() {
use Uri;
let valid_uri = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?amount=0.01&pjos=0&pj=HTTPS://EXAMPLE.COM/%23OH1QYPM5JXYNS754Y4R45QWE336QFX6ZR8DQGVQCULVZTV20TFVEYDMFQC";
let round_trip = valid_uri.parse::<Uri<_>>().unwrap().assume_checked().to_string();
println!("{}\n", valid_uri.parse::<Uri<_>>().unwrap().assume_checked().to_string());
assert_eq!(valid_uri, round_trip);
let uri = "Bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?6=q3Ҁf&pj=\u{3}\0\0\0\0\0\0http\r\r\r\r\r\r\r\r\r:\r\r\\.onion\\\\\\\\\\q3";
let round_trip = uri.parse::<Uri<_>>().unwrap().assume_checked().to_string();
println!("{}", uri.parse::<Uri<_>>().unwrap().assume_checked().to_string());
assert_eq!(uri, round_trip);
}
Activity
benalleng commentedon Jan 15, 2026
@spacebear21 prompted an llm which had this response which says that perhaps there is an even more minimal example which could demonstrate this.
upon further testing it does seem that this also fails. so minimally the test can just use
bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?a=1&pj=HTTPS://X.COM/benalleng commentedon Jan 15, 2026
I guess the question is whether this falls within spec or is otherwise acceptable as an implementation detail as it does not seem to be explicitly described in the spec regarding unknown Params.
i.e. should we maybe store "unknown_data" as a Param to be added back at the time of serialization?
https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki#forward-compatibility
Make Display byte-exact for a parsed URI
Make Display byte-exact for a parsed URI
Make Display byte-exact for a parsed URI
Make Display byte-exact for a parsed URI