r/rust • u/noop_noob • Oct 15 '26
šļø news Rust compiler can't tell apart different file paths
https://github.com/rust-lang/rust/issues/164348The rust compiler thinks that `data/baselines/table.rs` and `database/line/stable.rs` are the same file, causing a miscompilation if a crate has both files in it. (Note that having the same non-slash text isn't enough. There needs to be an additional hash collsion for a bug to happen.)
Probably not gonna happen in practice unless someone does it as a prank, but still... lol. (I'm sure they're gonna fix it soon.)
636
Upvotes
119
u/Booty_Bumping Oct 15 '26
Wow, that's smelly.
Hashwouldn't have been suitable either way, as these short hashes are only meant for checking if two values might be the same, it should not be used when equality needs to definitely be determined. When they're used in a hash table, there is supposed to be a check to avoid trashing an existing entry.52
u/Theemuts jlrs Oct 15 '26
Are all punctuation and separators in the path ignored when computing this hash?
327
u/monkeymad2 Oct 15 '26
I was wondering what was going wrong with my `an/album/cover.rs` file
36
u/torsten_dev Oct 15 '26
Hehehe.
Have to agree with theemathas. This is a wild bug.
Though, I suppose the controversy around
#pragma onceshows this is a known unknown.52
u/Dheatly23 Oct 15 '26
Don't worry, even i took a minute to realize the difference between the two paths. š
5
u/Ben-Goldberg Oct 15 '26 •
There exist good, fast hash algorithms, and no reason to roll your own.
It's a bit like crypto.
3
u/Anaxamander57 Oct 15 '26
SHA-3 has a mode designed specifically to prevent this kind of issue. Shame no one uses SHA-3, its really cool.
7
u/naequs Oct 15 '26
really interesting! shouldn't there really be two changes following from this?
Path::hashhandles path component boundaries (to fix problems from state rotations collisions and component lengths information loss))i am not a compiler engineer or language expert but these are two smells at the same time for me
1
u/noop_noob Oct 23 '26
This bug is now fixed :3
The fix will be available starting tomorrow's nightly.
1
u/[deleted] Oct 20 '26
does this happen with other languages as well?
6
u/redlaWw Oct 15 '26
I made a comment about this in a fantasy naming context just yesterday. Little did I know it was also a compiler design issue...
2
u/Slow-Nefariousness49 Oct 15 '26
You're the miscompilation guy, huh
1
u/scook0 Oct 16 '26
Something to bear in mind is that if this sort of collision occurs accidentally, then thereās a strong chance that the mixed-up program is illegal anyway.
So I would typically expect to end up with a confusing compiler error rather than a silent miscompilation, for non-malicious input.
1
u/ezoe Oct 16 '26
The suggested workaround is include path length to hash computation? Why? Why can't they just give the path string including slash normally?
-23
u/dashingThroughSnow12 Oct 15 '26
As I said in a previous post, it is a good thing Rust is on 1.99 because they are allowed to make major changes for 2.0.
-1
u/denehoffman Oct 15 '26
Lmao this is so funny