From cdc46a9dedc5210198ccec44b4e8ce5a8c90f02b Mon Sep 17 00:00:00 2001 From: Suika <32665912+suikammd@users.noreply.github.com> Date: Wed, 22 Sep 2021 16:06:51 +0800 Subject: [PATCH] io: add assert in copy_bidirectional that poll_write is sensible (#4125) --- tokio/src/io/util/copy.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tokio/src/io/util/copy.rs b/tokio/src/io/util/copy.rs index fbd77b5f2ea..d7fca2c3778 100644 --- a/tokio/src/io/util/copy.rs +++ b/tokio/src/io/util/copy.rs @@ -84,6 +84,14 @@ impl CopyBuffer { } } + // If pos larger than cap, this loop will never stop. + // In particular, user's wrong poll_write implementation returning + // incorrect written length may lead to thread blocking. + debug_assert!( + self.pos <= self.cap, + "writer returned length larger than input slice" + ); + // If we've written all the data and we've seen EOF, flush out the // data and finish the transfer. if self.pos == self.cap && self.read_done {