Skip to content
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ redis = { version = "1.7", default-features = false, features = ["tokio-comp", "
async-compression = { version = "0.4", features = ["tokio", "brotli", "zstd", "gzip", "zlib"] }
brotli = "9"
# RFC 9842 dcb: Brotli against a raw LZ77 dictionary, output identical to the
# reference encoder (the brotli crate's custom-dictionary encoder wrote corrupt streams)
# reference encoder; brotli's decoder checks each stream (brotli-decompressor
# 6.4.2 and later read a dictionary copy that runs on into the window)
mbrotli = { version = "0.5", default-features = false, features = ["std", "compression"] }
zstd = "0.14"
flate2 = "1.0"
Expand Down
10 changes: 5 additions & 5 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added fuzz/seeds/moq_control/publish-fill-empty-filter
Binary file not shown.
87 changes: 81 additions & 6 deletions src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,9 +914,7 @@ pub fn encode_dcb(data: &[u8], dict: &StoredDictionary, quality: u32) -> std::io
));
};

// mbrotli, whose output is the reference encoder's: the brotli crate's
// encoder wrote streams with a custom dictionary at some qualities that
// no decoder (the reference one included) could read. The reference
// mbrotli, whose output is the reference encoder's. The reference
// searches a dictionary only from quality 5 (below it the dictionary is
// ignored), so a lower configured quality is raised to 5 for dcb.
let quality = mbrotli::Quality::try_from(u8::try_from(quality.clamp(5, 11)).unwrap_or(11))
Expand Down Expand Up @@ -2096,9 +2094,7 @@ mod tests {
);
}

/// Every quality, small to large dictionaries: the brotli crate's encoder
/// wrote streams no decoder could read at quality 2 always and at quality
/// 5 from about 70 KB of dictionary; each must now decode to the body
/// Every quality, small to large dictionaries: each must decode to the body
#[test]
fn dcb_round_trips_at_every_quality_and_dictionary_size() {
let mut base = String::new();
Expand Down Expand Up @@ -2130,6 +2126,85 @@ mod tests {
}
}

/// A copy that starts in the dictionary and runs on into the stream's own
/// window: what the brotli crate's encoder writes at quality 2 against a
/// 64 KiB dictionary. Decoders before brotli-decompressor 6.4.2 refused
/// it as invalid (dropbox/rust-brotli-decompressor#104), which made
/// `decode_dcb` turn away valid streams.
#[test]
fn decode_dcb_reads_a_dictionary_copy_that_runs_into_the_window() {
use brotli::enc::encode::{
BrotliEncoderOperation, BrotliEncoderParameter, BrotliEncoderStateStruct,
};
use brotli::enc::StandardAlloc;

// Word-like text from an xorshift: the body begins as the dictionary does
fn text(mut seed: u64, len: usize) -> Vec<u8> {
let words = [
"fn ",
"let ",
"const ",
"return ",
"match ",
"impl ",
"pub ",
"struct ",
"async ",
"await ",
"self",
".map(",
"?;\n",
" => ",
"{\n",
"}\n",
"value",
"quic",
"brotli",
"dictionary",
];
let mut out = Vec::with_capacity(len);
while out.len() < len {
seed ^= seed << 13;
seed ^= seed >> 7;
seed ^= seed << 17;
let word = usize::try_from(seed % u64::try_from(words.len()).unwrap()).unwrap();
out.extend_from_slice(words[word].as_bytes());
}
out.truncate(len);
out
}
let dict = text(7, 64 << 10);
let mut body = text(7, 64 << 10);
body.extend_from_slice(&text(99, 25 << 10));

let mut encoder = BrotliEncoderStateStruct::new(StandardAlloc::default());
encoder.set_parameter(BrotliEncoderParameter::BROTLI_PARAM_QUALITY, 2);
encoder.set_parameter(BrotliEncoderParameter::BROTLI_PARAM_LGWIN, DCB_LGWIN);
encoder.set_custom_dictionary(dict.len(), &dict);
let mut stream = vec![0u8; body.len() * 2 + 1024];
let (mut avail_in, mut next_in, mut avail_out, mut next_out) =
(body.len(), 0usize, stream.len(), 0usize);
while !encoder.is_finished() {
assert!(encoder.compress_stream(
BrotliEncoderOperation::BROTLI_OPERATION_FINISH,
&mut avail_in,
&body,
&mut next_in,
&mut avail_out,
&mut stream,
&mut next_out,
&mut None,
&mut |_, _, _, _| (),
));
}
stream.truncate(next_out);

let mut encoded = DCB_MAGIC.to_vec();
encoded.extend_from_slice(&Sha256::digest(&dict));
encoded.extend_from_slice(&stream);
assert_eq!(decode_dcb(&encoded, &dict).unwrap(), body);
}

#[test]
fn compression_request_combines_multiple_accept_encoding_headers() {
let mut h = HeaderMap::new();
Expand Down
10 changes: 10 additions & 0 deletions src/moq/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,16 @@ mod tests {
}
}

/// A PUBLISH whose FILL_PARAMETERS hold a Range Filter of Length 0, which
/// outside a REQUEST_UPDATE is no filter and is not encoded again: the
/// input ClusterFuzzLite found on 2026-12-04
#[test]
fn control_check_takes_a_publish_with_an_empty_fill_filter() {
crate::moq::check::control(include_bytes!(
"../../fuzz/seeds/moq_control/publish-fill-empty-filter"
));
}

#[test]
fn the_pause_parameter_differs_by_draft() {
let p = Params {
Expand Down
35 changes: 26 additions & 9 deletions src/moq/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,35 @@ pub mod check {
|| !p.removed_filters.is_empty()
|| p.fill.as_deref().is_some_and(unencodable)
}
let skip = match &m {
// Every message that carries parameters: FILL_PARAMETERS "MAY
// appear in a SUBSCRIBE, SUBSCRIBE_TRACKS, PUBLISH, or
// REQUEST_UPDATE", and a Range Filter of Length 0 is a removal
// only in a REQUEST_UPDATE, no filter anywhere else, so it is
// never re-encoded
let params = match &m {
Message::Subscribe(r) | Message::Fetch(r) | Message::TrackStatus(r) => {
unencodable(&r.params)
Some(&r.params)
}
Message::SubscribeTracks(r) => unencodable(&r.params),
Message::RequestUpdate { params, .. } => unencodable(params),
// A Reason Phrase that was not UTF-8 is kept as text with
// replacement characters, which can outgrow its 1024 bytes
Message::PublishDone { reason, .. } => reason.contains('\u{FFFD}'),
Message::RequestError(e) => e.reason.contains('\u{FFFD}'),
_ => false,
Message::PublishNamespace(r)
| Message::SubscribeNamespace(r)
| Message::SubscribeTracks(r) => Some(&r.params),
Message::Publish(p) => Some(&p.params),
Message::SubscribeOk { params, .. }
| Message::FetchOk22 { params, .. }
| Message::Namespace { params, .. }
| Message::RequestUpdate { params, .. }
| Message::RequestOk { params, .. }
| Message::PublishStateNotify(params) => Some(params),
_ => None,
};
let skip = params.is_some_and(unencodable)
|| match &m {
// A Reason Phrase that was not UTF-8 is kept as text with
// replacement characters, which can outgrow its 1024 bytes
Message::PublishDone { reason, .. } => reason.contains('\u{FFFD}'),
Message::RequestError(e) => e.reason.contains('\u{FFFD}'),
_ => false,
};
if skip {
return;
}
Expand Down
8 changes: 7 additions & 1 deletion vendor/noq/VENDORED.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ when the proxy builds noq as a dependency.
- A server that rejects a ClientHello spanning two Initial packets (a hybrid
post-quantum key share makes most ClientHellos this size) says so with
CONNECTION_CLOSE too, on the path the connection began on, within the
anti-amplification limit; upstream n0-computer/noq#892.
anti-amplification limit, and again for each Initial the client sends
again there while the Initial keys exist (the first close was lost);
upstream n0-computer/noq#892.
- A handshake is confirmed once both the Initial and the Handshake keys are
gone. A connection that closed in the Initial space never had Handshake
keys, so it no longer counts as confirmed, and does not take probing or
migrating packets; upstream n0-computer/noq#920.
- RESET_STREAM_AT (draft-ietf-quic-reliable-stream-reset): the
`reset_stream_at` transport parameter (on by default), the frame both ways,
and `SendStream::reset_at`. This is a port of n0-computer/noq#843 onto this
Expand Down
Loading
Loading