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

Critical: async_bufreader::BufReader::poll_fill_buf: Destroys data. #10

Open
cheako opened this issue Nov 29, 2021 · 3 comments
Open

Critical: async_bufreader::BufReader::poll_fill_buf: Destroys data. #10

cheako opened this issue Nov 29, 2021 · 3 comments

Comments

@cheako
Copy link

cheako commented Nov 29, 2021

Line 174 s/this.buffer/this.buffer[*this.cap..]/.

@cheako
Copy link
Author

cheako commented Nov 29, 2021

let read = ready!(this.inner.poll_read(cx, this.buffer))?;

@cheako
Copy link
Author

cheako commented Nov 30, 2021

"AND", you can't use ready! as this is called multiple times in succession. Returning Ready and then Pending is a panic.

@cheako
Copy link
Author

cheako commented Nov 30, 2021

diff --git a/src/async_bufreader.rs b/src/async_bufreader.rs
index bb5557c..836c6fa 100644
--- a/src/async_bufreader.rs
+++ b/src/async_bufreader.rs
@@ -171,9 +171,16 @@ impl<R: AsyncRead> AsyncBufRead for BufReader<R> {
             }
         }
 
-        let read = ready!(this.inner.poll_read(cx, this.buffer))?;
-        *this.cap += read;
-
+        match this.inner.poll_read(cx, &mut this.buffer[*this.cap..]) {
+            Poll::Pending => {
+                /* This is supposed to let the compiler know pos can never be greater than cap... or something */
+                if *this.pos < *this.cap {
+                } else {
+                    return Poll::Pending;
+                }
+            }
+            Poll::Ready(read) => *this.cap += read?,
+        }
         Poll::Ready(Ok(&this.buffer[*this.pos..*this.cap]))
     }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant