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

Increment self.index before calling `Iterator::self.a.__iterator_ge… #81741

Conversation

sdroege
Copy link
Contributor

@sdroege sdroege commented Feb 4, 2021

t_unchecked in Zip TrustedRandomAccess specialization

Otherwise if Iterator::self.a.__iterator_get_unchecked panics the
index would not have been incremented yet and another call to
Iterator::next would read from the same index again, which is not
allowed according to the API contract of TrustedRandomAccess for
!Clone.

Fixes #81740

…t_unchecked` in `Zip` `TrustedRandomAccess` specialization

Otherwise if `Iterator::self.a.__iterator_get_unchecked` panics the
index would not have been incremented yet and another call to
`Iterator::next` would read from the same index again, which is not
allowed according to the API contract of `TrustedRandomAccess` for
`!Clone`.

Fixes rust-lang#81740
@rust-highfive
Copy link
Collaborator

r? @KodrAus

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 4, 2021
@camelid camelid added A-iterators Area: Iterators T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 5, 2021
@KodrAus
Copy link
Contributor

KodrAus commented Feb 10, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Feb 10, 2021

📌 Commit 86a4b27 has been approved by KodrAus

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 10, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Feb 11, 2021
…pecialization-panic-safety, r=KodrAus

Increment `self.index` before calling `Iterator::self.a.__iterator_ge…

…`t_unchecked` in `Zip` `TrustedRandomAccess` specialization

Otherwise if `Iterator::self.a.__iterator_get_unchecked` panics the
index would not have been incremented yet and another call to
`Iterator::next` would read from the same index again, which is not
allowed according to the API contract of `TrustedRandomAccess` for
`!Clone`.

Fixes rust-lang#81740
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Feb 12, 2021
…pecialization-panic-safety, r=KodrAus

Increment `self.index` before calling `Iterator::self.a.__iterator_ge…

…`t_unchecked` in `Zip` `TrustedRandomAccess` specialization

Otherwise if `Iterator::self.a.__iterator_get_unchecked` panics the
index would not have been incremented yet and another call to
`Iterator::next` would read from the same index again, which is not
allowed according to the API contract of `TrustedRandomAccess` for
`!Clone`.

Fixes rust-lang#81740
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2021
Rollup of 10 pull requests

Successful merges:

 - rust-lang#79775 (Fix injected errors when running doctests on a crate named after a keyword)
 - rust-lang#81012 (Stabilize the partition_point feature)
 - rust-lang#81479 (Allow casting mut array ref to mut ptr)
 - rust-lang#81506 (HWAddressSanitizer support)
 - rust-lang#81741 (Increment `self.index` before calling `Iterator::self.a.__iterator_ge…)
 - rust-lang#81850 (use RWlock when accessing os::env)
 - rust-lang#81911 (GAT/const_generics: Allow with_opt_const_param to return GAT param def_id)
 - rust-lang#82022 (Push a `char` instead of a `str` with len one into a String)
 - rust-lang#82023 (Remove unnecessary lint allow attrs on example)
 - rust-lang#82030 (Use `Iterator::all` instead of open-coding it)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0cfba2f into rust-lang:master Feb 13, 2021
@rustbot rustbot added this to the 1.52.0 milestone Feb 13, 2021
@RalfJung
Copy link
Member

Is it worth (or even possible) to add a testcase for this? I run the libcore test site in Miri every day, so it makes sense to have a test that "used to trigger UB" and thereby ensure that it does not do that any more.

Currently the test suite passes -- testing an iterator properly is hard, and I guess the test suite simply does not hit the code paths that cause UB.

@sdroege sdroege deleted the zip-trusted-random-access-specialization-panic-safety branch March 1, 2021 11:15
@sdroege
Copy link
Contributor Author

sdroege commented Mar 1, 2021

@RalfJung That would make sense but should probably wait until the other recent issues with the TrustedRandomAccess implementation are solved. At least one of them is touching exactly this code and there were discussions about changing the behaviour, which could very well break any test that would be added here.

I'll try to not forget and do that once those are fixed.

@sdroege
Copy link
Contributor Author

sdroege commented Mar 1, 2021

I was specifically thinking of #82289

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-iterators Area: Iterators S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Soundness issue in Zip::next() specialization
7 participants