]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-compression: zstd - Repair error codes if necessary
authorAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 4 Aug 2020 09:35:39 +0000 (12:35 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 6 Aug 2020 11:53:01 +0000 (14:53 +0300)
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.

src/lib-compression/Makefile.am
src/lib-compression/iostream-zstd-private.h [new file with mode: 0644]
src/lib-compression/istream-zstd.c
src/lib-compression/ostream-zstd.c

index fdebaa388ac5acf55b9ce8f29f1f6ae981d324f4..6c2e5e234eafbb304170a7cb27020619d02513b7 100644 (file)
@@ -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 (file)
index 0000000..cd0f691
--- /dev/null
@@ -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
index 61113da364f765314a9f97fb7423ade3ac216aac..6d1186e4b2454da0caaacb713b5acd9df6a601af 100644 (file)
@@ -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",
index 870a7b499186073a499e7619a431a65e5d7c8e51..ad48f9c3bec3881d4fe5c4078f4e47371ac7790d 100644 (file)
@@ -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",