From b99ece96b99b7015169d5e11d45078f21bfa6bd4 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 26 Jan 2022 10:43:50 -0800 Subject: [PATCH] converted checks into user validation generating error codes had to create a new error code for this condition, none of the existing ones were fitting enough. --- lib/common/error_private.c | 1 + lib/compress/zstd_compress.c | 4 ++-- lib/zstd_errors.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/common/error_private.c b/lib/common/error_private.c index 6d1135f8..f171e0dc 100644 --- a/lib/common/error_private.c +++ b/lib/common/error_private.c @@ -38,6 +38,7 @@ const char* ERR_getErrorString(ERR_enum code) case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported"; case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large"; case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small"; + case PREFIX(stabilityCondition_notRespected): return "pledged buffer stability condition is not respected"; case PREFIX(dictionary_corrupted): return "Dictionary is corrupted"; case PREFIX(dictionary_wrong): return "Dictionary mismatch"; case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples"; diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index e2a6d967..57f41a3b 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -5678,8 +5678,8 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx, && (totalInputSize < ZSTD_BLOCKSIZE_MAX) ) { /* not even reached one block yet */ if (cctx->stableIn_notConsumed) { /* not the first time */ /* check stable source guarantees */ - assert(input->src == cctx->expectedInBuffer.src); - assert(input->pos == cctx->expectedInBuffer.size); + RETURN_ERROR_IF(input->src != cctx->expectedInBuffer.src, stabilityCondition_notRespected, "stableInBuffer condition not respected: wrong src pointer"); + RETURN_ERROR_IF(input->pos != cctx->expectedInBuffer.size, stabilityCondition_notRespected, "stableInBuffer condition not respected: externally modified pos"); } /* pretend input was consumed, to give a sense forward progress */ input->pos = input->size; diff --git a/lib/zstd_errors.h b/lib/zstd_errors.h index fa3686b7..2ec0b0ab 100644 --- a/lib/zstd_errors.h +++ b/lib/zstd_errors.h @@ -66,6 +66,7 @@ typedef enum { ZSTD_error_tableLog_tooLarge = 44, ZSTD_error_maxSymbolValue_tooLarge = 46, ZSTD_error_maxSymbolValue_tooSmall = 48, + ZSTD_error_stabilityCondition_notRespected = 50, ZSTD_error_stage_wrong = 60, ZSTD_error_init_missing = 62, ZSTD_error_memory_allocation = 64,