From b3f74fd6d595cb7f067f4b78e1a8925044149e1f Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Sun, 8 Nov 2026 23:29:56 -0600 Subject: [PATCH] test(fleet-dispatch): salvage dechunked_len huge-size probe from closed PR #7524 (#6512) Re-applies the unique remainder of archive PR #7524: a characterization test pinning the unchecked arithmetic in dechunked_len on peer-declared chunk sizes usize::MAX and usize::MAX - 1, which panics in debug/test builds (issue #6512). Controls keep the existing pins and show dechunk() handles the same bytes safely. The probe's diagnostic println/catch_unwind reporting is normalized to assertions so the test carries an oracle; the checked-arithmetic fix in #6512 will trip it and update it deliberately. Closed PR #7524 was not reopened and its archive branch was not recreated. --- pkgs/fleet/crates/fleet-dispatch/src/lib.rs | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pkgs/fleet/crates/fleet-dispatch/src/lib.rs b/pkgs/fleet/crates/fleet-dispatch/src/lib.rs index b5eeb43cca..53d476f039 100644 --- a/pkgs/fleet/crates/fleet-dispatch/src/lib.rs +++ b/pkgs/fleet/crates/fleet-dispatch/src/lib.rs @@ -980,6 +980,35 @@ mod tests { assert!(err.message().contains("--prompt-file"), "{}", err.message()); } + /// Characterization test salvaged from archive PR #7524 (probe + /// worktree `probe-dispatch-dechunk-wt`, issue #6512): the + /// completeness checker does unchecked arithmetic on the + /// peer-declared chunk size, so the two largest `usize` values + /// overflow. Pinned here so the checked-arithmetic fix for #6512 + /// trips this test and updates it deliberately. + #[test] + fn probe_dechunked_len_huge_chunk_size() { + // controls: the existing pins + assert_eq!( + dechunked_len(b"4\r\nWiki\r\n5\r\npedia\r\n0\r\n\r\n"), + Some(9) + ); + assert_eq!(dechunked_len(b"4\r\nWi"), None); + // dechunk() itself guards the declared size before slicing: + assert_eq!(dechunk(b"ffffffffffffffff\r\nXX"), Vec::::new()); + // the completeness checker on the same peer-declared size: + let max = std::panic::catch_unwind(|| dechunked_len(b"ffffffffffffffff\r\nXX")); + assert!( + max.is_err(), + "dechunked_len must overflow-panic on usize::MAX until #6512 lands" + ); + let max_minus_one = std::panic::catch_unwind(|| dechunked_len(b"fffffffffffffffe\r\nXX")); + assert!( + max_minus_one.is_err(), + "dechunked_len must overflow-panic on usize::MAX - 1 until #6512 lands" + ); + } + #[test] fn usage_errors_exit_2_and_transport_3() { assert_eq!(usage("x").exit_code(), 2);