From: Aki Tuomi Date: Tue, 4 Aug 2020 09:35:39 +0000 (+0300) Subject: lib-compression: zstd - Repair error codes if necessary X-Git-Tag: 2.3.13~419 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1160ac3a3721ca6da53bb146eb67dd7a39c20248;p=thirdparty%2Fdovecot%2Fcore.git lib-compression: zstd - Repair error codes if necessary libzstd version numbers were pinned on 1.3.1, if we are compiled against version before that, and runtime is newer, we need to repair version numbers. A horrible hack that only allows using 1.3.1+ with old code. --- diff --git a/src/lib-compression/Makefile.am b/src/lib-compression/Makefile.am index fdebaa388a..6c2e5e234e 100644 --- a/src/lib-compression/Makefile.am +++ b/src/lib-compression/Makefile.am @@ -27,6 +27,9 @@ pkginc_lib_HEADERS = \ istream-zlib.h \ ostream-zlib.h +noinst_HEADERS = \ + iostream-zstd-private.h + pkglib_LTLIBRARIES = libdovecot-compression.la libdovecot_compression_la_SOURCES = libdovecot_compression_la_LIBADD = libcompression.la ../lib-dovecot/libdovecot.la $(COMPRESS_LIBS) diff --git a/src/lib-compression/iostream-zstd-private.h b/src/lib-compression/iostream-zstd-private.h new file mode 100644 index 0000000000..cd0f691ec8 --- /dev/null +++ b/src/lib-compression/iostream-zstd-private.h @@ -0,0 +1,25 @@ +#ifndef IOSTREAM_ZSTD_PRIVATE_H +#define IOSTREAM_ZSTD_PRIVATE_H 1 + +/* a horrible hack to fix issues when the installed libzstd is lot + newer than what we were compiled against. */ +static inline ZSTD_ErrorCode zstd_version_errcode(ZSTD_ErrorCode err) +{ +#if ZSTD_VERSION_NUMBER < 10301 + if (ZSTD_versionNumber() > 10300) { + /* reinterpret them */ + if (err == 10) + return ZSTD_error_prefix_unknown; + if (err == 32) + return ZSTD_error_dictionary_wrong; + if (err == 62) + return ZSTD_error_init_missing; + if (err == 64) + return ZSTD_error_memory_allocation; + return ZSTD_error_GENERIC; + } +#endif + return err; +} + +#endif diff --git a/src/lib-compression/istream-zstd.c b/src/lib-compression/istream-zstd.c index 61113da364..6d1186e4b2 100644 --- a/src/lib-compression/istream-zstd.c +++ b/src/lib-compression/istream-zstd.c @@ -10,6 +10,7 @@ #include "zstd.h" #include "zstd_errors.h" +#include "iostream-zstd-private.h" #ifndef HAVE_ZSTD_GETERRORCODE ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult) @@ -93,7 +94,7 @@ static void i_stream_zstd_close(struct iostream_private *stream, static void i_stream_zstd_read_error(struct zstd_istream *zstream, size_t err) { - ZSTD_ErrorCode errcode = ZSTD_getErrorCode(err); + ZSTD_ErrorCode errcode = zstd_version_errcode(ZSTD_getErrorCode(err)); const char *error = ZSTD_getErrorName(err); if (errcode == ZSTD_error_memory_allocation) i_fatal_status(FATAL_OUTOFMEM, "zstd.read(%s): Out of memory", diff --git a/src/lib-compression/ostream-zstd.c b/src/lib-compression/ostream-zstd.c index 870a7b4991..ad48f9c3be 100644 --- a/src/lib-compression/ostream-zstd.c +++ b/src/lib-compression/ostream-zstd.c @@ -10,6 +10,7 @@ #include "zstd.h" #include "zstd_errors.h" +#include "iostream-zstd-private.h" struct zstd_ostream { struct ostream_private ostream; @@ -27,7 +28,7 @@ struct zstd_ostream { static void o_stream_zstd_write_error(struct zstd_ostream *zstream, size_t err) { - ZSTD_ErrorCode errcode = ZSTD_getErrorCode(err); + ZSTD_ErrorCode errcode = zstd_version_errcode(ZSTD_getErrorCode(err)); const char *error = ZSTD_getErrorName(err); if (errcode == ZSTD_error_memory_allocation) i_fatal_status(FATAL_OUTOFMEM, "zstd.write(%s): Out of memory",