-
Notifications
You must be signed in to change notification settings - Fork 109
Cap calls to with_capacity with sane default #150
Cap calls to with_capacity with sane default #150
Conversation
924aa5f
to
cf2e0ea
Compare
This should be close to the final implementation, however I still need to write a test that would crash current HEAD, but passes with this change. |
Looks good to me, thanks! I'm fine merging with or without a test |
I have a few more questions: What happens inside of Vec and HashMap when they contain zero-sized types? My implementation lets them allocate all they want under the assumption that there isn't really any allocation being done. Is this a reasonable assumption? Do you want me to include the version number bump? |
For I'll include a separate version bump after this, so no need to include it here |
|
cf2e0ea
to
402f983
Compare
@alexcrichton I've updated the PR to cap with_capacity for zero-sized-types. |
Thanks! Did you want to add some tests as well? |
@alexcrichton I haven't yet, but I will tonight. |
For instances where the length of a collection must be obeyed, but is untrusted, calls to with_capacity() could result in OOM errors. This change makes it so that collections don't pre-allocate more than 1MB of memory.
402f983
to
4b2e953
Compare
@alexcrichton The code has been updated with a test. |
Thanks @TyOverby! |
@alexcrichton Could you bump the version number and publish to crates.io? I'd like to include a regression test in bincode for this scenario. |
Huh I thought I did that... sure though! |
For instances where the length of a collection must be obeyed, but is
untrusted, calls to with_capacity() could result in OOM errors.
This change makes it so that collections don't pre-allocate more than
1MB of memory.