-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Panic safety issue in Zip::next_back()
TrustedRandomAccess specialization
#86443
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Labels
A-iterators
Area: Iterators
C-bug
Category: This is a bug.
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.
Comments
How close is this to #85873? |
The same functions are involved but the aspects that interact to cause unsafety are quite different. @rustbot claim |
I agree, this is much closer to #81740. |
JohnTitor
added a commit
to JohnTitor/rust
that referenced
this issue
Jun 21, 2021
fix panic-safety in specialized Zip::next_back This was unsound since a panic in a.next_back() would result in the length not being updated which would then lead to the same element being revisited in the side-effect preserving code. fixes rust-lang#86443
the8472
added a commit
to the8472/rust
that referenced
this issue
May 16, 2025
Some history: The Zip TrustedRandomAccess specialization has tried to emulate the side-effects of the naive implementation for a long time, including backwards iteration. rust-lang#82292 tried to fix unsoundness (rust-lang#82291) in that side-effect-preservation code, but this introduced some panic-safety unsoundness (rust-lang#86443), but the fix rust-lang#86452 didn't fix it for nested Zip iterators (rust-lang#137255). Rather than piling yet another fix ontop of this heap of fixes this PR reduces the number of cases in which side-effects will be preserved; the necessary API guarantee change was approved in rust-lang#83791 but we haven't made use of that so far.
the8472
added a commit
to the8472/rust
that referenced
this issue
May 16, 2025
Some history: The Zip TrustedRandomAccess specialization has tried to emulate the side-effects of the naive implementation for a long time, including backwards iteration. rust-lang#82292 tried to fix unsoundness (rust-lang#82291) in that side-effect-preservation code, but this introduced some panic-safety unsoundness (rust-lang#86443), but the fix rust-lang#86452 didn't fix it for nested Zip iterators (rust-lang#137255). Rather than piling yet another fix ontop of this heap of fixes this PR reduces the number of cases in which side-effects will be preserved; the necessary API guarantee change was approved in rust-lang#83791 but we haven't made use of that so far.
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Labels
A-iterators
Area: Iterators
C-bug
Category: This is a bug.
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.
Uh oh!
There was an error while loading. Please reload this page.
rust/library/core/src/iter/adapters/zip.rs
Lines 296 to 301 in 312b894
rust/library/core/src/iter/adapters/zip.rs
Lines 235 to 244 in 312b894
Yet another soundness bug in Zip's TRA specialization. Line 300 is not called when line 298 panics. This leaves
self.a_len
outdated, which results in calling__iterator_get_unchecked()
with an invalid index in line 242.Here is a playground link that demonstrates creating two mutable references to the same memory location without unsafe code.
The text was updated successfully, but these errors were encountered: