]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
converted checks into user validation generating error codes
authorYann Collet <cyan@fb.com>
Wed, 26 Jan 2022 18:43:50 +0000 (10:43 -0800)
committerYann Collet <cyan@fb.com>
Wed, 26 Jan 2022 18:43:50 +0000 (10:43 -0800)
had to create a new error code for this condition,
none of the existing ones were fitting enough.

lib/common/error_private.c
lib/compress/zstd_compress.c
lib/zstd_errors.h

index 6d1135f8c37330f49535695a4fa7fc4e09bc66cc..f171e0dce38b6d830802a53d5e3280eb8a4b3893 100644 (file)
@@ -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";
index e2a6d9675c549dc82898dac08018d01023efa6b7..57f41a3b343af7eac5df502f04ab0f4d64315952 100644 (file)
@@ -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;
index fa3686b7724399c7e60358fdd912f087c9ad9122..2ec0b0ab16843efd6df0a58736565b932a5e9beb 100644 (file)
@@ -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,