feat(compress): move deprecated block-size formula to Rust

Keep validation of the applied compression parameters in C and delegate the context-free minimum calculation through a narrow ABI leaf. Preserve the public getter and deprecated block-compression paths.

Test Plan:

- cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression

- cargo clippy --manifest-path rust/Cargo.toml --no-default-features --features compression --all-targets

- cargo +nightly fmt --manifest-path rust/Cargo.toml

- make -B -C lib -j2 lib

- make -C tests -j2 fuzzer

- tests/fuzzer -s4560 -t47 -i48 -v
This commit is contained in:
2026-07-18 08:33:07 +02:00
parent 7f22db844d
commit 33c937bc87
2 changed files with 20 additions and 1 deletions
+18
View File
@@ -900,6 +900,17 @@ pub extern "C" fn ZSTD_rust_params_resolveMaxBlockSize(maxBlockSize: usize) -> u
}
}
#[inline]
fn get_block_size(max_block_size: usize, window_log: u32) -> usize {
max_block_size.min(1usize << window_log)
}
/// Pure leaf for the deprecated `ZSTD_getBlockSize()` path.
#[no_mangle]
pub extern "C" fn ZSTD_rust_params_getBlockSize(maxBlockSize: usize, windowLog: u32) -> usize {
get_block_size(maxBlockSize, windowLog)
}
fn estimate_cdict_size_from_cparams(
dict_size: usize,
cparams: ZSTD_compressionParameters,
@@ -1319,4 +1330,11 @@ mod tests {
assert_eq!(ZSTD_rust_params_maxNbSeq(100, 4, 0), 25);
assert_eq!(ZSTD_rust_params_resolveMaxBlockSize(0), 128 * 1024);
}
#[test]
fn block_size_uses_the_smaller_configured_limit() {
assert_eq!(ZSTD_rust_params_getBlockSize(64 * 1024, 17), 64 * 1024);
assert_eq!(ZSTD_rust_params_getBlockSize(128 * 1024, 16), 64 * 1024);
assert_eq!(ZSTD_rust_params_getBlockSize(128 * 1024, 17), 128 * 1024);
}
}