Skip to content

Commit

Permalink
Fix #74: UnexpectedEnd when EOS, but data buf is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
stammw committed Jan 14, 2022
1 parent cbe4407 commit fa48008
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion h3/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ where
match (data, end) {
(None, true) => Poll::Ready(Ok(None)),
(None, false) => Poll::Pending,
(Some(d), true) if d.remaining() < self.remaining_data => {
(Some(d), true)
if d.remaining() < self.remaining_data && !self.bufs.has_remaining() =>
{
Poll::Ready(Err(Error::UnexpectedEnd))
}
(Some(d), _) => {
Expand Down Expand Up @@ -478,6 +480,38 @@ mod tests {
);
}

#[tokio::test]
async fn poll_data_eos_but_buffered_data() {
let mut recv = FakeRecv::default();
let mut buf = BytesMut::with_capacity(64);

FrameType::DATA.encode(&mut buf);
VarInt::from(4u32).encode(&mut buf);
buf.put_slice(&b"bo"[..]);
recv.chunk(buf.clone().freeze());

let mut stream = FrameStream::new(recv);

assert_poll_matches!(
|mut cx| stream.poll_next(&mut cx),
Ok(Some(Frame::Data(PayloadLen(4))))
);

buf.truncate(0);
buf.put_slice(&b"dy"[..]);
stream.bufs.push_bytes(&mut buf.freeze());

assert_poll_matches!(
|mut cx| to_bytes(stream.poll_data(&mut cx)),
Ok(Some(b)) if &*b == b"bo"
);

assert_poll_matches!(
|mut cx| to_bytes(stream.poll_data(&mut cx)),
Ok(Some(b)) if &*b == b"dy"
);
}

// Helpers

#[derive(Default)]
Expand Down

0 comments on commit fa48008

Please sign in to comment.