Skip to content

Commit

Permalink
Return an error instead of panicking when stuck in a CONTINUATION loop
Browse files Browse the repository at this point in the history
It is not rare a large header can trigger such a CONTINUATION loop.
While the stream cannot recover from this issue, returning an error
instead of panicking makes the impact radius under better control.
  • Loading branch information
eaufavor authored and seanmonstar committed Feb 26, 2021
1 parent bcaaaf6 commit 1122970
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/codec/framed_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ where
match self.encoder.unset_frame() {
ControlFlow::Continue => (),
ControlFlow::Break => break,
ControlFlow::EndlessLoopHeaderTooBig => {
return Poll::Ready(Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
UserError::HeaderTooBig,
)));
}
}
}

Expand Down Expand Up @@ -193,6 +199,7 @@ where
enum ControlFlow {
Continue,
Break,
EndlessLoopHeaderTooBig,
}

impl<B> Encoder<B>
Expand Down Expand Up @@ -222,7 +229,10 @@ where
// If *only* the CONTINUATION frame header was
// written, and *no* header fields, we're stuck
// in a loop...
panic!("CONTINUATION frame write loop; header value too big to encode");
tracing::warn!(
"CONTINUATION frame write loop; header value too big to encode"
);
return ControlFlow::EndlessLoopHeaderTooBig;
}

self.next = Some(Next::Continuation(continuation));
Expand Down

0 comments on commit 1122970

Please sign in to comment.