diff --git a/CPP/7zip/Compress/ZstdDecoder.cpp b/CPP/7zip/Compress/ZstdDecoder.cpp index 6430c817..071b0f6c 100644 --- a/CPP/7zip/Compress/ZstdDecoder.cpp +++ b/CPP/7zip/Compress/ZstdDecoder.cpp @@ -1,4 +1,4 @@ -// (C) 2016 - 2018 Tino Reichardt +// (C) 2016 - 2020 Tino Reichardt #define DEBUG 0 @@ -110,8 +110,22 @@ HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream, zOut.pos = 0; result = ZSTD_decompressStream(_ctx, &zOut, &zIn); - if (ZSTD_isError(result)) - return E_FAIL; + if (ZSTD_isError(result)) { + switch (ZSTD_getErrorCode(result)) { + /* @Igor: would be nice, if we have an API to store the errmsg */ + case ZSTD_error_memory_allocation: + return E_OUTOFMEMORY; + case ZSTD_error_version_unsupported: + case ZSTD_error_frameParameter_unsupported: + return E_NOTIMPL; + case ZSTD_error_frameParameter_windowTooLarge: + case ZSTD_error_parameter_unsupported: + case ZSTD_error_parameter_outOfBound: + return E_INVALIDARG; + default: + return E_FAIL; + } + } #if DEBUG printf("res = %u\n", (unsigned)result); diff --git a/CPP/7zip/Compress/ZstdDecoder.h b/CPP/7zip/Compress/ZstdDecoder.h index 351e3701..fe16ebf0 100644 --- a/CPP/7zip/Compress/ZstdDecoder.h +++ b/CPP/7zip/Compress/ZstdDecoder.h @@ -3,6 +3,7 @@ #define ZSTD_STATIC_LINKING_ONLY #include "../../../C/Alloc.h" #include "../../../C/zstd/zstd.h" +#include "../../../C/zstd/zstd_errors.h" #include "../../Windows/System.h" #include "../../Common/Common.h" diff --git a/CPP/7zip/Compress/ZstdEncoder.cpp b/CPP/7zip/Compress/ZstdEncoder.cpp index 7babd22a..5e9494f5 100644 --- a/CPP/7zip/Compress/ZstdEncoder.cpp +++ b/CPP/7zip/Compress/ZstdEncoder.cpp @@ -1,8 +1,8 @@ -// (C) 2016 - 2018 Tino Reichardt +// (C) 2016 - 2020 Tino Reichardt #define DEBUG 0 -#if DEBUG +#if 0 #include #endif @@ -349,7 +349,22 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, } err = ZSTD_compressStream2(_ctx, &outBuff, &inBuff, ZSTD_todo); - if (ZSTD_isError(err)) return E_FAIL; + if (ZSTD_isError(err)) { + switch (ZSTD_getErrorCode(err)) { + /* @Igor: would be nice, if we have an API to store the errmsg */ + case ZSTD_error_memory_allocation: + return E_OUTOFMEMORY; + case ZSTD_error_version_unsupported: + case ZSTD_error_frameParameter_unsupported: + return E_NOTIMPL; + case ZSTD_error_frameParameter_windowTooLarge: + case ZSTD_error_parameter_unsupported: + case ZSTD_error_parameter_outOfBound: + return E_INVALIDARG; + default: + return E_FAIL; + } + } #if DEBUG printf("err=%u ", (unsigned)err);