refactor(compress): move end directive validation to Rust
Project the scalar ZSTD_compressStream2 end directive into Rust and keep C responsible for the private streaming context, existing parameter error, and diagnostic text. The Rust range policy preserves the original unsigned enum validation for continue, flush, and end. Test Plan: ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings; cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check; make -j1; ./tests/rustLibSmoke; make -j1 -C tests test (all shell tests, large streaming tests, native tester, fuzzer phases, and zstream tester passed).
This commit is contained in:
@@ -769,6 +769,15 @@ size_t ZSTD_compressStream2_c(ZSTD_CCtx* cctx,
|
||||
ZSTD_outBuffer* output,
|
||||
ZSTD_inBuffer* input,
|
||||
ZSTD_EndDirective endOp);
|
||||
typedef struct {
|
||||
int endOp;
|
||||
} ZSTD_rust_compressStream2PolicyState;
|
||||
int ZSTD_rust_compressStream2Policy(
|
||||
const ZSTD_rust_compressStream2PolicyState* state);
|
||||
typedef char ZSTD_rust_compress_stream2_policy_state_layout[
|
||||
(offsetof(ZSTD_rust_compressStream2PolicyState, endOp) == 0
|
||||
&& sizeof(ZSTD_rust_compressStream2PolicyState) == sizeof(int))
|
||||
? 1 : -1];
|
||||
int ZSTD_rust_simpleCompress2Level(const void* cctx, size_t srcSize);
|
||||
typedef int (*ZSTD_rust_simpleCompress2Level_f)(const void* cctx, size_t srcSize);
|
||||
typedef struct {
|
||||
@@ -8266,7 +8275,10 @@ size_t ZSTD_compressStream2_c( ZSTD_CCtx* cctx,
|
||||
/* check conditions */
|
||||
RETURN_ERROR_IF(output->pos > output->size, dstSize_tooSmall, "invalid output buffer");
|
||||
RETURN_ERROR_IF(input->pos > input->size, srcSize_wrong, "invalid input buffer");
|
||||
RETURN_ERROR_IF((U32)endOp > (U32)ZSTD_e_end, parameter_outOfBound, "invalid endDirective");
|
||||
{ ZSTD_rust_compressStream2PolicyState const state = {(int)endOp};
|
||||
RETURN_ERROR_IF(!ZSTD_rust_compressStream2Policy(&state),
|
||||
parameter_outOfBound, "invalid endDirective");
|
||||
}
|
||||
assert(cctx != NULL);
|
||||
|
||||
/* transparent initialization stage */
|
||||
|
||||
Reference in New Issue
Block a user