From 9416195221552d6fc8b44b899360d3d14f7401ea Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 27 Sep 2017 10:35:56 -0700 Subject: [PATCH] changed error code when pos<=size condition is not respected Now pointing towards src_size or dst_size, instead of error_GENERIC. --- lib/common/error_private.c | 5 +++-- lib/common/zstd_errors.h | 3 ++- lib/decompress/zstd_decompress.c | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/common/error_private.c b/lib/common/error_private.c index 8045e445..11f7cdab 100644 --- a/lib/common/error_private.c +++ b/lib/common/error_private.c @@ -30,14 +30,15 @@ const char* ERR_getErrorString(ERR_enum code) case PREFIX(init_missing): return "Context should be init first"; case PREFIX(memory_allocation): return "Allocation error : not enough memory"; case PREFIX(stage_wrong): return "Operation not authorized at current processing stage"; - case PREFIX(dstSize_tooSmall): return "Destination buffer is too small"; - case PREFIX(srcSize_wrong): return "Src size is incorrect"; 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(dictionary_corrupted): return "Dictionary is corrupted"; case PREFIX(dictionary_wrong): return "Dictionary mismatch"; case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples"; + case PREFIX(dstSize_tooSmall): return "Destination buffer is too small"; + case PREFIX(srcSize_wrong): return "Src size is incorrect"; + /* following error codes are not stable and may be removed or changed in a future version */ case PREFIX(frameIndex_tooLarge): return "Frame index is too large"; case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking"; case PREFIX(maxCode): diff --git a/lib/common/zstd_errors.h b/lib/common/zstd_errors.h index bde4304c..4bcb7769 100644 --- a/lib/common/zstd_errors.h +++ b/lib/common/zstd_errors.h @@ -63,9 +63,10 @@ typedef enum { ZSTD_error_memory_allocation = 64, ZSTD_error_dstSize_tooSmall = 70, ZSTD_error_srcSize_wrong = 72, + /* following error codes are not stable and may be removed or changed in a future version */ ZSTD_error_frameIndex_tooLarge = 100, ZSTD_error_seekableIO = 102, - ZSTD_error_maxCode = 120 /* never EVER use this value directly, it may change in future versions! Use ZSTD_isError() instead */ + ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */ } ZSTD_ErrorCode; /*! ZSTD_getErrorCode() : diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 0380f6a1..332bf860 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -2407,12 +2407,12 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB if (input->pos > input->size) { /* forbidden */ DEBUGLOG(5, "in: pos: %u vs size: %u", (U32)input->pos, (U32)input->size); - return ERROR(GENERIC); + return ERROR(srcSize_wrong); } if (output->pos > output->size) { /* forbidden */ DEBUGLOG(5, "out: pos: %u vs size: %u", (U32)output->pos, (U32)output->size); - return ERROR(GENERIC); + return ERROR(dstSize_tooSmall); } DEBUGLOG(5, "input size : %u", (U32)(input->size - input->pos));