fix(compress): select dispatch strategy from input size
The Rust dispatch gate for ZSTD_compress2 and complete-input ZSTD_compressStream2 calls was selecting compression parameters with an unknown content size. For the 30-byte level-4 CCtx reuse case that chooses the dfast strategy, while the actual source size selects greedy; the Rust frame then emitted different output from the C-owned ZSTD_compressCCtx path. Pass the actual source size through both helper ABIs. The one-shot and complete stream entry points now select the same strategy as C, while the existing sentinel keeps every non-fast/non-dfast configuration on the original C fallback. The existing fuzzer test 56 exercises the regression without modifying the shared C test harness. Test Plan: - `cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression` -- 348 passed. - Compression clippy for the library, benches, and tests, followed by nightly fmt and the repeated three clippy checks -- passed. - `make -C tests -j2 fuzzer` and `./tests/fuzzer -s4560 -t56 -i57 -v` -- passed; the 30-byte test-56 regression now completes. - `./tests/fuzzer -s4142 -t63 -i64 -v` -- passed all 64 focused cases. - `make -C lib -j2 lib-mt` and `make -C lib -j2 lib-nomt` -- passed. - `make -C tests -j2 test-zstream` -- passed 84 deterministic, 4,385 first randomized, and 8,137 new-API randomized cases. - `make -C tests -j2 test-fuzzer` reaches test 113's flat-dictionary efficiency assertion with concurrent unstaged LDM changes; test 56 passes.
This commit is contained in:
@@ -43,7 +43,7 @@ unsafe extern "C" {
|
||||
fn ZSTD_rust_compressCCtxStrategy(src_size: usize, compression_level: c_int) -> c_int;
|
||||
fn ZSTD_rust_resetCCtxForSimpleCompressionSession(cctx: *mut c_void) -> usize;
|
||||
fn ZSTD_rust_markSimpleCompression2Complete(cctx: *mut c_void);
|
||||
fn ZSTD_rust_simpleCompress2Level(cctx: *const c_void) -> c_int;
|
||||
fn ZSTD_rust_simpleCompress2Level(cctx: *const c_void, src_size: usize) -> c_int;
|
||||
fn ZSTD_compress_usingDict(
|
||||
cctx: *mut c_void,
|
||||
dst: *mut c_void,
|
||||
@@ -54,7 +54,7 @@ unsafe extern "C" {
|
||||
dict_size: usize,
|
||||
compression_level: c_int,
|
||||
) -> usize;
|
||||
fn ZSTD_rust_simpleCompressStream2Level(cctx: *const c_void) -> c_int;
|
||||
fn ZSTD_rust_simpleCompressStream2Level(cctx: *const c_void, src_size: usize) -> c_int;
|
||||
fn ZSTD_compress2_c(
|
||||
cctx: *mut c_void,
|
||||
dst: *mut c_void,
|
||||
@@ -1195,7 +1195,7 @@ pub unsafe extern "C" fn ZSTD_compress2(
|
||||
|
||||
#[cfg(not(test))]
|
||||
{
|
||||
let level = unsafe { ZSTD_rust_simpleCompress2Level(cctx.cast_const()) };
|
||||
let level = unsafe { ZSTD_rust_simpleCompress2Level(cctx.cast_const(), src_size) };
|
||||
if level != c_int::MIN {
|
||||
let reset = unsafe { ZSTD_rust_resetCCtxForSimpleCompressionSession(cctx) };
|
||||
if ERR_isError(reset) {
|
||||
@@ -1244,10 +1244,10 @@ pub unsafe extern "C" fn ZSTD_compressStream2(
|
||||
return ERROR(ZstdErrorCode::SrcSizeWrong);
|
||||
}
|
||||
|
||||
let src_size = input_ref.size - input_ref.pos;
|
||||
if end_op == ZSTD_E_END {
|
||||
let level = unsafe { ZSTD_rust_simpleCompressStream2Level(cctx.cast_const()) };
|
||||
let level = unsafe { ZSTD_rust_simpleCompressStream2Level(cctx.cast_const(), src_size) };
|
||||
if level != c_int::MIN {
|
||||
let src_size = input_ref.size - input_ref.pos;
|
||||
let dst_capacity = output_ref.size - output_ref.pos;
|
||||
let bound = ZSTD_compressBound(src_size);
|
||||
if !ERR_isError(bound) && dst_capacity >= bound {
|
||||
|
||||
Reference in New Issue
Block a user