Skip to content

Commit 23ca593

Browse files
authored
Merge pull request #294 from link2xt/link2xt/miniz_oxide-consumes-all-input
fix(tokio): attempt to decode from internal state even if nothing was read
2 parents 3337a1b + ed83d67 commit 23ca593

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/tokio/bufread/generic/decoder.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,37 @@ impl<R: AsyncBufRead, D: Decode> Decoder<R, D> {
6565
) -> Poll<Result<()>> {
6666
let mut this = self.project();
6767

68+
let mut first = true;
69+
6870
loop {
6971
*this.state = match this.state {
7072
State::Decoding => {
71-
let input = ready!(this.reader.as_mut().poll_fill_buf(cx))?;
72-
if input.is_empty() {
73+
let input = if first {
74+
&[][..]
75+
} else {
76+
ready!(this.reader.as_mut().poll_fill_buf(cx))?
77+
};
78+
79+
if input.is_empty() && !first {
7380
// Avoid attempting to reinitialise the decoder if the reader
7481
// has returned EOF.
7582
*this.multiple_members = false;
83+
7684
State::Flushing
7785
} else {
7886
let mut input = PartialBuffer::new(input);
79-
let done = this.decoder.decode(&mut input, output)?;
87+
let done = this.decoder.decode(&mut input, output).or_else(|err| {
88+
// ignore the first error, occurs when input is empty
89+
// but we need to run decode to flush
90+
if first {
91+
Ok(false)
92+
} else {
93+
Err(err)
94+
}
95+
})?;
96+
97+
first = false;
98+
8099
let len = input.written().len();
81100
this.reader.as_mut().consume(len);
82101
if done {

0 commit comments

Comments
 (0)