check endDirective in ZSTD_compressStream2()
fix #2297 also : - `assert()` `endDirective` in `ZSTD_compressStream_internal()`, for debug mode - add relevant tests
This commit is contained in:
@@ -3937,6 +3937,7 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
||||
assert(zcs->outBuffSize > 0);
|
||||
assert(output->pos <= output->size);
|
||||
assert(input->pos <= input->size);
|
||||
assert((U32)flushMode <= (U32)ZSTD_e_end);
|
||||
|
||||
while (someMoreWork) {
|
||||
switch(zcs->streamStage)
|
||||
@@ -4083,9 +4084,10 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
||||
{
|
||||
DEBUGLOG(5, "ZSTD_compressStream2, endOp=%u ", (unsigned)endOp);
|
||||
/* check conditions */
|
||||
RETURN_ERROR_IF(output->pos > output->size, GENERIC, "invalid buffer");
|
||||
RETURN_ERROR_IF(input->pos > input->size, GENERIC, "invalid buffer");
|
||||
assert(cctx!=NULL);
|
||||
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");
|
||||
assert(cctx != NULL);
|
||||
|
||||
/* transparent initialization stage */
|
||||
if (cctx->streamStage == zcss_init) {
|
||||
|
||||
+2
-1
@@ -677,8 +677,9 @@ typedef enum {
|
||||
* - Compression parameters cannot be changed once compression is started (save a list of exceptions in multi-threading mode)
|
||||
* - output->pos must be <= dstCapacity, input->pos must be <= srcSize
|
||||
* - output->pos and input->pos will be updated. They are guaranteed to remain below their respective limit.
|
||||
* - endOp must be a valid directive
|
||||
* - When nbWorkers==0 (default), function is blocking : it completes its job before returning to caller.
|
||||
* - When nbWorkers>=1, function is non-blocking : it just acquires a copy of input, and distributes jobs to internal worker threads, flush whatever is available,
|
||||
* - When nbWorkers>=1, function is non-blocking : it copies a portion of input, distributes jobs to internal worker threads, flush to output whatever is available,
|
||||
* and then immediately returns, just indicating that there is some data remaining to be flushed.
|
||||
* The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte.
|
||||
* - Exception : if the first call requests a ZSTD_e_end directive and provides enough dstCapacity, the function delegates to ZSTD_compress2() which is always blocking.
|
||||
|
||||
Reference in New Issue
Block a user