From ab9e2243ed3f2e2d028749b5dda93dd5a9d9c362 Mon Sep 17 00:00:00 2001 From: ddidderr Date: Mon, 20 Jul 2026 15:15:17 +0200 Subject: [PATCH] fix(mt): publish filled input before job creation The Rust MT stream scheduler now copies input into the reusable round buffer through its local projection and publishes the final filled count when the outer call returns. Job creation, however, is a C callback invoked during that same scheduler call. It still inspected `mtctx->inBuff.filled` while preparing the job, so the count lagged behind the bytes Rust had just copied and the existing preparation assertion fired in the multiple-file CLI path. Publish the callback's `srcSize` into the C context before constructing the job projection. This restores the ordering of the former C copy callback: the context count is current before job preparation, while the existing end-of-call result publication remains available for paths that do not create a job. Test Plan: - `cc -fsyntax-only -Werror=incompatible-pointer-types -Ilib -Ilib/common -Ilib/compress -Ilib/decompress -Ilib/dict -Ilib/legacy lib/compress/zstdmt_compress.c` -- passed - `git diff --check` and `git diff --cached --check` -- passed - `make -j1 -C tests test` reproduced the pre-fix assertion in `ZSTDMT_prepareCompressionJob`; the capped full-suite rerun is pending --- lib/compress/zstdmt_compress.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index d146456ec..d0e951630 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -2723,6 +2723,11 @@ static size_t ZSTDMT_createCompressionJob(void* opaque, size_t srcSize, unsigned { ZSTDMT_CCtx* const mtctx = (ZSTDMT_CCtx*)opaque; ZSTD_EndDirective const endOp = (ZSTD_EndDirective)end; + /* Rust fills the reusable input range in its local projection before + * calling this C-owned job-construction callback. Publish that count + * before the callback prepares a job and checks the C context. */ + assert(srcSize <= mtctx->inBuff.buffer.capacity); + mtctx->inBuff.filled = srcSize; ZSTDMT_RustCreateJobProjection const projection = { mtctx->doneJobID, mtctx->nextJobID,