Make the chunk size non-zero by type; reject overflowing sizes

--chunk 0 made every chunk 'full' while empty, so the chunker emitted
empty chunks (and empty zstd frames) forever -- 11 MB in 3 s from a
424-byte source. parse_size now returns NonZeroUsize, which flows through
SendOptions into RecordAlignedChunker, so a zero target can't reach the
cut logic. parse_size and parse_duration also use checked_mul instead of
wrapping on absurd inputs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ericandClaude Opus 5.5 committed 2026-11-13 16:11:17 -05:00
1 parent 6a80aaf461
commit b46d6a936c
3 files changed
+41 -28

No files matched your search

+5 -4
View File
@@ -7,6 +7,7 @@ use crate::zstd_frame::{compress_frame, MARKER_FRAME};
use anyhow::{bail, Result};
use std::fs::File;
use std::io::Write;
use std::num::NonZeroUsize;
use std::path::PathBuf;
use std::sync::{mpsc, Arc};
use std::time::Duration;
@@ -23,7 +24,7 @@ pub struct SendOptions {
pub is_partial: bool,
pub final_source_path: PathBuf,
pub compress: bool,
pub chunk_target: usize,
pub chunk_target: NonZeroUsize,
/// How long kept-but-undersized output may wait before being sent
/// anyway. See `Chunker::should_flush`.
pub flush_after: Duration,
@@ -357,7 +358,7 @@ mod tests {
is_partial: false,
final_source_path: src.clone(),
compress: true,
chunk_target: 512, // small target to force multiple frames
chunk_target: NonZeroUsize::new(512).unwrap(), // small target to force multiple frames
flush_after: crate::chunker::DEFAULT_FLUSH,
level: crate::zstd_frame::DEFAULT_LEVEL,
filter: PacketFilter::match_all(),
@@ -485,7 +486,7 @@ mod tests {
is_partial: false,
final_source_path: src.clone(),
compress: true,
chunk_target: 512,
chunk_target: NonZeroUsize::new(512).unwrap(),
flush_after: crate::chunker::DEFAULT_FLUSH,
level: crate::zstd_frame::DEFAULT_LEVEL,
filter: ip_filter(&["1.1.1.1"]),
@@ -580,7 +581,7 @@ mod tests {
is_partial: true,
final_source_path: final_src.clone(),
compress: true,
chunk_target: 512,
chunk_target: NonZeroUsize::new(512).unwrap(),
flush_after: crate::chunker::DEFAULT_FLUSH,
level: crate::zstd_frame::DEFAULT_LEVEL,
filter: PacketFilter::parse(&[], &["02:00:00:00:00:aa".to_string()]).unwrap(),