-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix a potential overflow in core::str::Searcher::new
#16701
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
The overflow is mitigated by checking a sufficient condition for the less relation. Given the term `A - B < C` (`A`, `B` and `C` fixed size unsigned integers) one can check whether it holds, by evaluating `A < C || A - B < C`.
What overflow is this fixing? When |
That is, if |
It's impossible for the length to be 20 below |
Is it theoretically impossible for the length to be 20 below If it's theoretically possible then maybe some guideline on "what can we expect from array lengths" would be good so it's consistent over all Rust code. (Maybe: All arrays of objects with size |
It's impossible because On modern operating systems, the kernel gets half of the address space and userspace gets the other half, so saying |
If #16715 is fixed, this can be replaced by a comment instead of the check. |
As-is, I believe that this fix is not necessary, @tbu- can you update this PR to have a comment instead? |
@alexcrichton The PR author is writing correct code and I think it's something we should observe better throughout libcore/libstd (I've hunted such problems before). Being correct one time too many would be a good start. |
Closing due to inactivity, but feel free to reopen with my comment addressed! |
The overflow is mitigated by checking a sufficient condition for the less
relation.
Given the term
A - B < C
(A
,B
andC
fixed size unsigned integers) onecan check whether it holds, by evaluating
A < C || A - B < C
.