-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
properly handle EOF in BufReader::peek #130042
Conversation
previously this would cause an infinite loop due to it being unable to read `n` bytes.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Amanieu (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
@lolbinarycat Can we get a test with the code that would cause the infinite loop? |
I think a better algorithm would be to remove the loop and do this instead:
Always backshifting before reading will minimize the number of reads on the underlying reader, and we can avoid backshifting if enough bytes are already available in the buffer. If the user really wants to issue multiple reads to the underlying reader then we should have a separate |
@workingjubilee I actually added such a test to the end of the doctest, trying to peek once EOF has been reached would trigger the bug. @Amanieu performing multiple reads is the entire purpose of this feature. if you don't care about robustness against short reads, you can just hackily use |
any status on moving this forward? either we should merge this fix, or mark if we want to change the behavior or api of this feature, that should be discussed in a separate issue. |
Sure, let's just fix this for now, we can discuss the API separately. @bors r+ |
…=Amanieu properly handle EOF in BufReader::peek previously this would cause an infinite loop due to it being unable to read `n` bytes.
/// `n` must be less than `capacity`. | ||
/// `n` must be less than or equal to `capacity`. | ||
/// | ||
/// the returned slice may be less than `n` bytes long if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the" should be capitalized, shouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, nice catch. i plan on doing another pass at the documentation once the finer details of the behavior are worked out, possibly earlier.
however, this is a very minor typo, and i don't think it's worth blocking such a critical fix on such a minor typo.
Rollup of 6 pull requests Successful merges: - rust-lang#130042 (properly handle EOF in BufReader::peek) - rust-lang#130061 (Add `NonNull` convenience methods to `Box` and `Vec`) - rust-lang#130202 (set `download-ci-llvm = true` by default on "library" and "tools" profiles) - rust-lang#130214 (MaybeUninit::zeroed: mention that padding is not zeroed) - rust-lang#130353 (Make some lint doctests compatible with `--stage=0`) - rust-lang#130370 (unstable-book: `trait_upcasting` example should not have `#![allow(incomplete_features)]`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 6 pull requests Successful merges: - rust-lang#130042 (properly handle EOF in BufReader::peek) - rust-lang#130061 (Add `NonNull` convenience methods to `Box` and `Vec`) - rust-lang#130202 (set `download-ci-llvm = true` by default on "library" and "tools" profiles) - rust-lang#130214 (MaybeUninit::zeroed: mention that padding is not zeroed) - rust-lang#130353 (Make some lint doctests compatible with `--stage=0`) - rust-lang#130370 (unstable-book: `trait_upcasting` example should not have `#![allow(incomplete_features)]`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#130042 - lolbinarycat:bufreaker_peek_eof, r=Amanieu properly handle EOF in BufReader::peek previously this would cause an infinite loop due to it being unable to read `n` bytes.
chill, bors. |
@bors r- |
@bors retry |
@bors r- |
previously this would cause an infinite loop due to it being unable to read
n
bytes.