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

Avoid overflow in std::iter::Skip::count #68469

Merged
merged 1 commit into from
Jan 24, 2020
Merged

Conversation

ollie27
Copy link
Member

@ollie27 ollie27 commented Jan 22, 2020

The call to count on the inner iterator can overflow even if Skip itself would return less that usize::max_value() items.

Fixes #68139

The call to `count` on the inner iterator can overflow even if `Skip` itself would return less that `usize::max_value()` items.
@rust-highfive
Copy link
Collaborator

r? @sfackler

(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 Jan 22, 2020
@timvermeulen
Copy link
Contributor

Won't this return a wrong value whenever self.n > 0 and self.iter.nth(self.n - 1) is a Some? Say, for (0..10).skip(3).

@ollie27
Copy link
Member Author

ollie27 commented Jan 23, 2020

Won't this return a wrong value whenever self.n > 0 and self.iter.nth(self.n - 1) is a Some? Say, for (0..10).skip(3).

It looks correct to me. In that example it will call nth(2) which will return Some(2) which is the third item. At that point every item that needs to be skipped will have been skipped so count() will then return 7.

@sfackler
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 23, 2020

📌 Commit 9d3e844 has been approved by sfackler

@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 Jan 23, 2020
@timvermeulen
Copy link
Contributor

Huh yeah, not sure what I was thinking yesterday.

tmandry added a commit to tmandry/rust that referenced this pull request Jan 24, 2020
Avoid overflow in `std::iter::Skip::count`

The call to `count` on the inner iterator can overflow even if `Skip` itself would return less that `usize::max_value()` items.

Fixes rust-lang#68139
tmandry added a commit to tmandry/rust that referenced this pull request Jan 24, 2020
Avoid overflow in `std::iter::Skip::count`

The call to `count` on the inner iterator can overflow even if `Skip` itself would return less that `usize::max_value()` items.

Fixes rust-lang#68139
bors added a commit that referenced this pull request Jan 24, 2020
Rollup of 7 pull requests

Successful merges:

 - #68424 (Suggest borrowing `Vec<NonCopy>` in for loop)
 - #68438 (Account for non-types in substs for opaque type error messages)
 - #68469 (Avoid overflow in `std::iter::Skip::count`)
 - #68473 (Enable ASan on Fuchsia)
 - #68479 (Implement `unused_parens` for block return values)
 - #68483 (Add my (@flip1995) name to .mailmap)
 - #68500 (Clear out std, not std tools)

Failed merges:

r? @ghost
@bors bors merged commit 9d3e844 into rust-lang:master Jan 24, 2020
@ollie27 ollie27 deleted the skip_count branch January 24, 2020 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std::iter::Skip::count can overflow even if the iterator would return less that usize::max_value() items
5 participants