-
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
Undefined Behavior in Vec::insert if passed an index outside of its capacity #122760
Comments
rustbot
added
the
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
label
Mar 20, 2024
jwong101
changed the title
Undefined Behavior in Vec::insert if passed an index outside of it's capacity
Undefined Behavior in Vec::insert if passed an index outside of its capacity
Mar 20, 2024
Noratrieb
added
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
and removed
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
labels
Mar 20, 2024
rustbot
added
the
I-prioritize
Issue: Indicates that prioritization has been requested for this issue.
label
Mar 20, 2024
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
Mar 20, 2024
…ng-usize-max, r=Nilstrieb Add `usize::MAX` arg tests for Vec Tests to prevent recurrence of the UB from the rust-lang#122760 issue. I skipped the `with_capacity`, `drain`, `reserve`, etc. APIs because they actually had a good assortment of tests earlier in the same file. r? Nilstrieb
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
Mar 20, 2024
…jubilee,Nilstrieb fix OOB pointer formed in Vec::index Move the length check to before using `index` with `ptr::add` to prevent an out of bounds pointer from being formed. Fixes rust-lang#122760
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
Mar 20, 2024
…ng-usize-max, r=Nilstrieb Add `usize::MAX` arg tests for Vec Tests to prevent recurrence of the UB from the rust-lang#122760 issue. I skipped the `with_capacity`, `drain`, `reserve`, etc. APIs because they actually had a good assortment of tests earlier in the same file. r? Nilstrieb
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
Mar 20, 2024
…ng-usize-max, r=Nilstrieb Add `usize::MAX` arg tests for Vec Tests to prevent recurrence of the UB from the rust-lang#122760 issue. I skipped the `with_capacity`, `drain`, `reserve`, etc. APIs because they actually had a good assortment of tests earlier in the same file. r? Nilstrieb
apiraino
removed
the
I-prioritize
Issue: Indicates that prioritization has been requested for this issue.
label
Mar 20, 2024
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Mar 20, 2024
…bilee,Nilstrieb fix OOB pointer formed in Vec::index Move the length check to before using `index` with `ptr::add` to prevent an out of bounds pointer from being formed. Fixes rust-lang#122760
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Mar 20, 2024
…ng-usize-max, r=Nilstrieb Add `usize::MAX` arg tests for Vec Tests to prevent recurrence of the UB from the rust-lang#122760 issue. I skipped the `with_capacity`, `drain`, `reserve`, etc. APIs because they actually had a good assortment of tests earlier in the same file. r? Nilstrieb
jhpratt
added a commit
to jhpratt/rust
that referenced
this issue
Mar 21, 2024
…ng-usize-max, r=Nilstrieb Add `usize::MAX` arg tests for Vec Tests to prevent recurrence of the UB from the rust-lang#122760 issue. I skipped the `with_capacity`, `drain`, `reserve`, etc. APIs because they actually had a good assortment of tests earlier in the same file. r? Nilstrieb
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Mar 21, 2024
Rollup merge of rust-lang#122765 - workingjubilee:test-for-vec-handling-usize-max, r=Nilstrieb Add `usize::MAX` arg tests for Vec Tests to prevent recurrence of the UB from the rust-lang#122760 issue. I skipped the `with_capacity`, `drain`, `reserve`, etc. APIs because they actually had a good assortment of tests earlier in the same file. r? Nilstrieb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried this code:
I expected to see this happen:
The program should panic, but not have any undefined behavior.
Instead, this happened:
Miri reports that the program triggers undefined behavior.
MIRI Backtrace
Meta
It seems like the issue is here:
rust/library/alloc/src/vec/mod.rs
Lines 1554 to 1563 in a77c20c
The length check needs to happen before the computation of ptr::add, since it's undefined behavior if the new pointer is out of bounds of the allocation or overflows the address space.
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: