-
Notifications
You must be signed in to change notification settings - Fork 13.3k
close a vulnerability where HashMap::from_iter wasn't being randomized #15257
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
Conversation
I've been thinking of doing something like this for the facade to allow insertion of The one final piece of the puzzle would be to parameterize |
I just tried that, and it's going to result is us having to explicitly declare hashmap types. For example this snippet needs an explicit type:
Which is a bit unfortunate. Would it be easier to have an explicit generic |
Hm, that is indeed unfortunate. I was hoping for something like this:
The key part being that the I suppose if you can define methods on type aliases it may work out as you could have |
@@ -23,5 +23,6 @@ pub use core_collections::{priority_queue, ringbuf, smallintmap, treemap, trie}; | |||
pub use self::hashmap::{HashMap, HashSet}; | |||
pub use self::lru_cache::LruCache; | |||
|
|||
pub mod hash; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is available at std::hash
, so why export it here?
It turns out that HashMap's from_iter implementation was being initialized without the sip keys being randomized. This adds a custom default hasher that should avoid this potential vulnerability.
@alexcrichton: I updated the PR to remove |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
//! Generic hashing support. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a nice doc-comment in collections::hash
which sadly won't get included like this, perhaps it could be moved over to this module instead?
@alexcrichton: updated to include the documentation. |
While `HashMap::new` and `HashMap::with_capacity` were being initialized with a random `SipHasher`, it turns out that `HashMap::from_iter` was just using the default instance of `SipHasher`, which wasn't randomized. This closes that bug, and also inlines some important methods.
[lsp-server] Ignore 'Content-Length' case this is a trivial PR meant to address issue rust-lang#15197: the 'Content-Length' header field should probably be treated as case-insensitive
While
HashMap::new
andHashMap::with_capacity
were being initialized with a randomSipHasher
, it turns out thatHashMap::from_iter
was just using the default instance ofSipHasher
, which wasn't randomized. This closes that bug, and also inlines some important methods.