From d5669af3522da309f6d1da58facba5a5a2773b00 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 29 Sep 2026 17:49:56 +0200 Subject: [PATCH] B3 fix: pin what cargo-mutants found unpinned in the framed route reader The header-size bound was tested only against answers that also stopped short, so it never had to hold on its own; the interrupted-read retry was exercised by no reader that could be interrupted. The header test now sends an honest, whole answer whose headers alone exceed the bound, and a scripted reader pins the retry and the silent/refused split at the Answer boundary. Co-Authored-By: Claude Sonnet 5 --- src/drivers.rs | 86 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 8 deletions(-) diff --git a/src/drivers.rs b/src/drivers.rs index 2429c9a..f06e019 100644 --- a/src/drivers.rs +++ b/src/drivers.rs @@ -8627,14 +8627,6 @@ mod tests { ] .concat(), ), - ( - "headers over the bound together", - [ - b"HTTP/1.1 200 OK\r\n".to_vec(), - b"X: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n".repeat(600), - ] - .concat(), - ), ("headers that are not UTF-8", b"HTTP/1.1 200 OK\r\nX: \xff\r\n\r\n".to_vec()), ("a status that is not UTF-8", b"HTTP/1.1 \xff\r\n\r\n".to_vec()), ] { @@ -8642,6 +8634,84 @@ mod tests { } } + /// Every header line is small and the answer is honest and whole; only the + /// headers' total size refuses it. + #[test] + fn headers_that_are_over_their_bound_together_refuse_an_otherwise_honest_answer() { + let filler = b"X: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"; + let answer_with = |lines: usize| { + move |id: &str| { + let body = honest_body(id); + let mut reply = + format!("HTTP/1.1 200 OK\r\nContent-Length: {}\r\n", body.len()).into_bytes(); + reply.extend_from_slice(&filler.repeat(lines)); + reply.extend_from_slice(b"\r\n"); + reply.extend_from_slice(&body); + reply + } + }; + let lines = ROUTE_HTTP_MAX_HEADER_BYTES / filler.len(); + challenge(scripted_peer(answer_with(lines / 2)), |_| {}).expect("headers inside the bound"); + assert_refused( + challenge(scripted_peer(answer_with(lines * 2)), |_| {}), + "headers over the bound together", + ); + } + + /// A reader that fails `interruptions` times with `kind`, then serves `bytes`. + struct Flaky { + kind: ErrorKind, + interruptions: usize, + bytes: &'static [u8], + } + + impl Read for Flaky { + fn read(&mut self, buffer: &mut [u8]) -> std::io::Result { + if self.interruptions > 0 { + self.interruptions -= 1; + return Err(self.kind.into()); + } + let served = self.bytes.len().min(buffer.len()); + buffer[..served].copy_from_slice(&self.bytes[..served]); + self.bytes = &self.bytes[served..]; + Ok(served) + } + } + + #[test] + fn an_interrupted_read_is_retried_and_any_other_failure_is_a_stopped_peer() { + let mut interrupted = Answer::new(Flaky { + kind: ErrorKind::Interrupted, + interruptions: 3, + bytes: b"abcd", + }); + let mut buffer = [0_u8; 4]; + interrupted.read_all(&mut buffer, "in the test").expect("the read is retried"); + assert_eq!(&buffer, b"abcd"); + + // Before any byte the peer is silent; after some, it is refused. + let mut failing = Answer::new(Flaky { + kind: ErrorKind::TimedOut, + interruptions: 1, + bytes: b"abcd", + }); + assert!(matches!( + failing.read_all(&mut buffer, "in the test"), + Err(ChallengeFailure::Silent(_)) + )); + let mut failing = Answer::new(Flaky { + kind: ErrorKind::TimedOut, + interruptions: 0, + bytes: b"ab", + }); + let mut wanted = [0_u8; 3]; + failing.read_all(&mut wanted[..2], "in the test").expect("two bytes"); + assert!(matches!( + failing.read_all(&mut wanted[2..], "in the test"), + Err(ChallengeFailure::Refused(_)) + )); + } + fn assert_silent(outcome: Result, why: &str) { assert!( matches!(outcome, Err(ChallengeFailure::Silent(_))),