Skip to content
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

Fix soundness issues in sized chunks and ringbuffer #13

Merged
merged 2 commits into from
Feb 13, 2021

Conversation

vorner
Copy link
Contributor

@vorner vorner commented Nov 5, 2020

This fixes (hopefully) part of #11, + something I've seen on the way.

I'm not entirely sure if this is the right way:

  • I think I could make the unit and pair methods compile-time unavailable on too small arrays, instead of panicking. I don't worry about the performance (the check should be optimized out, as both numbers are constants at compile time), but the user would get the error sooner. On the other hand, some kind of generic code would have harder time, because it would also have to declare the same trait bounds as I'd have added and they won't be exactly nice. So I'm not sure if it's worth it.
  • Part of the panic safety now leaks existing elements. That's better than dropping uninitialized ones (the latter is UB), but certainly not great. I can try to give it some more effort and figure a way how to fully recover from a panic. But I'm afraid that would come with performance penalty (I hope the the additional increments by one won't be measurable/will disappear in most cases as most practical ExactSizeIterators don't panic and rustc will be able to prove it).

I'll have a look at the InlineArray in a separate pull request.

The unit, pair and From<InlineArray> now check the capacity, because one
could create 0-capacity or small capacity arrays.
@vorner vorner changed the title Check min size Fix soundness issues in sized chunks and ringbuffer Nov 5, 2020
@vorner vorner force-pushed the check-min-size branch 2 times, most recently from 4444694 to 9668113 Compare November 5, 2020 20:05
Panic safety in the insert_from and Clone. The insert_from leaks
elements in case of panic. This is more of a quickfix than proper
solutions :-(.
@kornelski kornelski merged commit 99e593c into bodil:master Feb 13, 2021
@vorner vorner deleted the check-min-size branch February 14, 2021 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants