Closed
Description
The implementation of type_id from #10182 uses SipHash on various parameters depending on the type. The output size of SipHash is only 64-bits, however, making it feasible to find collisions via a Birthday Attack. I believe the code below demonstrates a collision in the type_id value of two different ty_structs:
use std::hash;
use std::hash::Streaming;
// I believe that this pretty much the same thing as hash_crate_independent() in ty.rs
// for a ty_struct on a 64-bit platform
fn hash_struct(local_hash: &str, node: u64) -> u64 {
let mut state = hash::default_state();
state.input([18]);
state.input(local_hash.as_bytes());
do node.iter_bytes(true) |bytes| { state.input(bytes); true };
state.result_u64()
}
fn main() {
// This represents two structures with different node values from a crate with a
// local_hash value of "local" that end up getting the same hash and thus,
// I think, the same type_id
assert!(hash_struct("local", 0x9e02c8943c336302) == hash_struct("local", 0x366a806b1d5f1b2));
}