-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hash
implementation for Path
ignores path separators
#127254
Comments
There may be some quality-of-implementation argument about avoiding collisions for data patterns that are likely to coexist. I'm not sure if it is the case here, I'll have to think about it. And even if it is then there also is the matter of making such a avoidance fast. The current code is optimized for speed. |
I think that's a fair point, but the current implementation already goes out if its way to create equal hashes for paths like Thanks for taking a look! |
The difference is that Things comparing inequal does not require the Hash to be different. Instead it's only a matter of quality-of-implementation whether they produce distinct hashes, not a matter of correctness. |
That's a great point, thanks for clarifying. I agree this is not a "correctness" problem, but more of a practical consideration for the hashing algorithm. |
Rollup merge of rust-lang#127297 - the8472:path-new-hash, r=Nilstrieb Improve std::Path's Hash quality by avoiding prefix collisions This adds a bit rotation to the already existing state so that the same sequence of characters chunked at different offsets into separate path components results in different hashes. The tests are from rust-lang#127255 Closes rust-lang#127254
I tried this code:
I expected to see this happen: Different hashes since these represent different paths.
Instead, this happened: The hashes are equal.
This makes sense for redundant path separators (e.g.
//
), but not for all path separators.I added a test case to the standard library — which fails.
The relevant code is probably around
rust/library/std/src/path.rs
Lines 3112 to 3114 in 6292b2a
Meta
I tested this on stable (1.79.0), nightly (1.81.0), and on
master
(6292b2a).Discovered via astral-sh/ruff#12158
The text was updated successfully, but these errors were encountered: