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

Backport #1667 to 0.9.x #1668

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,12 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
rust: [stable, beta, 1.59.0]
rust: [stable, beta]
exclude:
- os: macos-latest
rust: beta
- os: macos-latest
rust: 1.59.0
- os: windows-latest
rust: beta
- os: windows-latest
rust: 1.59.0

runs-on: ${{ matrix.os }}

Expand All @@ -70,6 +66,21 @@ jobs:
command: test
args: --manifest-path fuzz/Cargo.toml

msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: "1.63.0"
override: true
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/cargo@v1
with:
command: check
args: --lib --all-features -p quinn-udp -p quinn-proto -p quinn

lint:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "quinn-proto"
version = "0.9.4"
version = "0.9.5"
license = "MIT OR Apache-2.0"
repository = "https://github.com/quinn-rs/quinn"
description = "State machine for the QUIC transport protocol"
keywords = ["quic"]
categories = [ "network-programming", "asynchronous" ]
workspace = ".."
edition = "2021"
rust-version = "1.59"
rust-version = "1.63"

[package.metadata.docs.rs]
all-features = true
Expand Down
26 changes: 13 additions & 13 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,15 @@ impl Connection {
return Ok(());
}
State::Closed(_) => {
for frame in frame::Iter::new(packet.payload.freeze()) {
for result in frame::Iter::new(packet.payload.freeze()) {
let frame = match result {
Ok(frame) => frame,
Err(err) => {
debug!("frame decoding error: {err:?}");
continue;
}
};

if let Frame::Padding = frame {
continue;
};
Expand Down Expand Up @@ -2291,7 +2299,8 @@ impl Connection {
debug_assert_ne!(packet.header.space(), SpaceId::Data);
let payload_len = packet.payload.len();
let mut ack_eliciting = false;
for frame in frame::Iter::new(packet.payload.freeze()) {
for result in frame::Iter::new(packet.payload.freeze()) {
let frame = result?;
let span = match frame {
Frame::Padding => continue,
_ => Some(trace_span!("frame", ty = %frame.ty())),
Expand All @@ -2316,11 +2325,6 @@ impl Connection {
self.state = State::Draining;
return Ok(());
}
Frame::Invalid { ty, reason } => {
let mut err = TransportError::FRAME_ENCODING_ERROR(reason);
err.frame = Some(ty);
return Err(err);
}
_ => {
let mut err =
TransportError::PROTOCOL_VIOLATION("illegal frame type in handshake");
Expand Down Expand Up @@ -2349,7 +2353,8 @@ impl Connection {
let mut close = None;
let payload_len = payload.len();
let mut ack_eliciting = false;
for frame in frame::Iter::new(payload) {
for result in frame::Iter::new(payload) {
let frame = result?;
let span = match frame {
Frame::Padding => continue,
_ => Some(trace_span!("frame", ty = %frame.ty())),
Expand Down Expand Up @@ -2397,11 +2402,6 @@ impl Connection {
}
}
match frame {
Frame::Invalid { ty, reason } => {
let mut err = TransportError::FRAME_ENCODING_ERROR(reason);
err.frame = Some(ty);
return Err(err);
}
Frame::Crypto(frame) => {
self.read_crypto(SpaceId::Data, &frame, payload_len)?;
}
Expand Down
1 change: 0 additions & 1 deletion quinn-proto/src/connection/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ impl FrameStats {
Frame::PathResponse(_) => self.path_response += 1,
Frame::Close(_) => self.connection_close += 1,
Frame::HandshakeDone => self.handshake_done += 1,
Frame::Invalid { .. } => {}
}
}
}
Expand Down
32 changes: 23 additions & 9 deletions quinn-proto/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ pub enum Frame {
PathResponse(u64),
Close(Close),
Datagram(Datagram),
Invalid { ty: Type, reason: &'static str },
HandshakeDone,
}

Expand Down Expand Up @@ -197,7 +196,6 @@ impl Frame {
Crypto(_) => Type::CRYPTO,
NewToken { .. } => Type::NEW_TOKEN,
Datagram(_) => Type(*DATAGRAM_TYS.start()),
Invalid { ty, .. } => ty,
HandshakeDone => Type::HANDSHAKE_DONE,
}
}
Expand Down Expand Up @@ -516,7 +514,7 @@ impl Crypto {
}
}

pub struct Iter {
pub(crate) struct Iter {
// TODO: ditch io::Cursor after bytes 0.5
bytes: io::Cursor<Bytes>,
last_ty: Option<Type>,
Expand Down Expand Up @@ -721,25 +719,39 @@ impl Iter {
}

impl Iterator for Iter {
type Item = Frame;
type Item = Result<Frame, InvalidFrame>;
fn next(&mut self) -> Option<Self::Item> {
if !self.bytes.has_remaining() {
return None;
}
match self.try_next() {
Ok(x) => Some(x),
Ok(x) => Some(Ok(x)),
Err(e) => {
// Corrupt frame, skip it and everything that follows
self.bytes = io::Cursor::new(Bytes::new());
Some(Frame::Invalid {
ty: self.last_ty.unwrap(),
Some(Err(InvalidFrame {
ty: self.last_ty,
reason: e.reason(),
})
}))
}
}
}
}

#[derive(Debug)]
pub(crate) struct InvalidFrame {
pub(crate) ty: Option<Type>,
pub(crate) reason: &'static str,
}

impl From<InvalidFrame> for TransportError {
fn from(err: InvalidFrame) -> Self {
let mut te = Self::FRAME_ENCODING_ERROR(err.reason);
te.frame = err.ty;
te
}
}

fn scan_ack_blocks(buf: &mut io::Cursor<Bytes>, largest: u64, n: usize) -> Result<(), IterErr> {
let first_block = buf.get_var()?;
let mut smallest = largest.checked_sub(first_block).ok_or(IterErr::Malformed)?;
Expand Down Expand Up @@ -890,7 +902,9 @@ mod test {
ce: 12,
};
Ack::encode(42, &ranges, Some(&ECN), &mut buf);
let frames = Iter::new(Bytes::from(buf)).collect::<Vec<_>>();
let frames = Iter::new(Bytes::from(buf))
.collect::<Result<Vec<_>, _>>()
.unwrap();
assert_eq!(frames.len(), 1);
match frames[0] {
Frame::Ack(ref ack) => {
Expand Down
2 changes: 1 addition & 1 deletion quinn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ keywords = ["quic"]
categories = [ "network-programming", "asynchronous" ]
workspace = ".."
edition = "2021"
rust-version = "1.59"
rust-version = "1.63"

[package.metadata.docs.rs]
all-features = true
Expand Down