From 105495cc77b2ef48bdc5943b00120135304566e1 Mon Sep 17 00:00:00 2001 From: yuzh <1109426275@qq.com> Date: Mon, 28 Apr 2025 08:02:39 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=E9=87=8D=E6=9E=84KAEZlib=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yuzh <1109426275@qq.com> --- KAEZlib/src/kaezip_adapter.c | 20 ++++++++++---------- KAEZlib/src/v1/kaezip_deflate.c | 13 ++----------- KAEZlib/src/v1/kaezip_inflate.c | 10 ++-------- 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/KAEZlib/src/kaezip_adapter.c b/KAEZlib/src/kaezip_adapter.c index 56f5eac..4c7314d 100644 --- a/KAEZlib/src/kaezip_adapter.c +++ b/KAEZlib/src/kaezip_adapter.c @@ -61,7 +61,7 @@ int kz_deflateInit2_(z_streamp strm, int level, int metho, int windowBit, int me switch (g_platform) { case HW_NONE: - ret = lz_deflateInit2_(strm, level, metho, windowBit, memLevel, strategy, version, stream_size); + ret = Z_OK; break; case HW_V1: ret = kz_deflateInit2_v1(strm, level, metho, windowBit, memLevel, strategy, version, stream_size); @@ -93,7 +93,7 @@ int kz_deflate(z_streamp strm, int flush) switch (g_platform) { case HW_NONE: - ret = lz_deflate(strm, flush); + ret = Z_CALL_SOFT; break; case HW_V1: kaezip_ctx = getDeflateKaezipCtx(strm); @@ -101,7 +101,7 @@ int kz_deflate(z_streamp strm, int flush) ret = kz_deflate_v1(strm, flush); } else { US_WARN("HW_V1: using lz_deflate! kaezip_ctx is %lu, flush is %d", kaezip_ctx, flush); - ret = lz_deflate(strm, flush); + ret = Z_CALL_SOFT; } break; case HW_V2: @@ -122,7 +122,7 @@ int kz_deflateEnd(z_streamp strm) switch (g_platform) { case HW_NONE: - ret = lz_deflateEnd(strm); + ret = Z_OK; break; case HW_V1: ret = kz_deflateEnd_v1(strm); @@ -145,7 +145,7 @@ int kz_deflateReset(z_streamp strm) switch (g_platform) { case HW_NONE: - ret = lz_deflateReset(strm); + ret = Z_OK; break; case HW_V1: ret = kz_deflateReset_v1(strm); @@ -169,7 +169,7 @@ int kz_inflateInit2_(z_streamp strm, int windowBits, const char *version, int st switch (g_platform) { case HW_NONE: - ret = lz_inflateInit2_(strm, windowBits, version, stream_size); + ret = Z_OK; break; case HW_V1: ret = kz_inflateInit2_v1(strm, windowBits, version, stream_size); @@ -199,7 +199,7 @@ int kz_inflate(z_streamp strm, int flush) switch (g_platform) { case HW_NONE: - ret = lz_inflate(strm, flush); + ret = Z_CALL_SOFT; break; case HW_V1: alg_type = kz_getAutoInflateAlgType(strm); @@ -209,7 +209,7 @@ int kz_inflate(z_streamp strm, int flush) ret = kz_inflate_v1(strm, flush); } else { US_WARN("HW_V1: using lz_inflate! kaezip_ctx is %lu, flush is %d", kaezip_ctx, flush); - ret = lz_inflate(strm, flush); + ret = Z_CALL_SOFT; } break; case HW_V2: @@ -230,7 +230,7 @@ int kz_inflateEnd(z_streamp strm) switch (g_platform) { case HW_NONE: - ret = lz_inflateEnd(strm); + ret = Z_OK; break; case HW_V1: ret = kz_inflateEnd_v1(strm); @@ -253,7 +253,7 @@ int kz_inflateReset(z_streamp strm) switch (g_platform) { case HW_NONE: - ret = lz_inflateReset(strm); + ret = Z_OK; break; case HW_V1: ret = kz_inflateReset_v1(strm); diff --git a/KAEZlib/src/v1/kaezip_deflate.c b/KAEZlib/src/v1/kaezip_deflate.c index 95a604a..fb5faa4 100644 --- a/KAEZlib/src/v1/kaezip_deflate.c +++ b/KAEZlib/src/v1/kaezip_deflate.c @@ -57,11 +57,6 @@ int kz_deflateInit2_v1(z_streamp strm, int level, if (windowBits == -8) { // raw-deflate and 8 will get Z_STREAM_ERROR in lz_deflateInit2_(see deflate.c Line 301) windowBits = -9; } - int ret = lz_deflateInit2_(strm, level, method, windowBits, memLevel, strategy, version, stream_size); - if (ret != Z_OK) { - US_ERR("zlib deflate init failed windowbits %d! ret is %d!", windowBits, ret); - return Z_ERRNO; - } int alg_comp_type = kaezip_winbits2algtype(windowBits); if ((alg_comp_type == WCRYPTO_NONE) || (alg_comp_type == WCRYPTO_RAW_DEFLATE && !kaezip_checkCpu_isV2())) { @@ -156,18 +151,14 @@ int kz_deflate_v1(z_streamp strm, int flush) int kz_deflateEnd_v1(z_streamp strm) { - int ret; - int comp_alg_type = -1; kaezip_ctx_t *kaezip_ctx = (kaezip_ctx_t *)getDeflateKaezipCtx(strm); if (kaezip_ctx != NULL) { US_DEBUG("kaezip deflate end"); - comp_alg_type = kaezip_ctx->comp_alg_type; // WCRYPTO_RAW_DEFLATE kaezip_put_ctx(kaezip_ctx); } setDeflateKaezipCtx(strm, 0); - ret = lz_deflateEnd(strm); - return comp_alg_type == WCRYPTO_RAW_DEFLATE ? Z_OK : ret; + return Z_OK; } int ZEXPORT kz_deflateReset_v1(z_streamp strm) @@ -178,7 +169,7 @@ int ZEXPORT kz_deflateReset_v1(z_streamp strm) kaezip_init_ctx(kaezip_ctx); } - return lz_deflateReset(strm); + return Z_OK; } static void kaezip_deflate_set_fmt_header(z_streamp strm, int comp_alg_type) diff --git a/KAEZlib/src/v1/kaezip_inflate.c b/KAEZlib/src/v1/kaezip_inflate.c index bdcc255..cdb31e6 100644 --- a/KAEZlib/src/v1/kaezip_inflate.c +++ b/KAEZlib/src/v1/kaezip_inflate.c @@ -52,12 +52,6 @@ int ZEXPORT kz_inflateInit2_v1(z_streamp strm, int windowBits, const char *versi static const int GZIP_INFLATE_MAX_AUTO_WBITS = 47; static const int GZIP_INFLATE_MIN_AUTO_WBITS = 32; - int ret = lz_inflateInit2_(strm, windowBits, version, stream_size); - if (unlikely(ret != Z_OK)) { - US_ERR("lz_inflateInit2_ error, windowBits %d! ret is %d!", windowBits, ret); - return Z_ERRNO; - } - setInflateKaezipCtx(strm, (unsigned long)0); if (windowBits >= GZIP_INFLATE_MIN_AUTO_WBITS && windowBits <= GZIP_INFLATE_MAX_AUTO_WBITS) { return Z_OK; @@ -132,7 +126,7 @@ int kz_inflateEnd_v1(z_streamp strm) } setInflateKaezipCtx(strm, 0); - return lz_inflateEnd(strm); + return Z_OK; } int ZEXPORT kz_inflateReset_v1(z_streamp strm) @@ -143,7 +137,7 @@ int ZEXPORT kz_inflateReset_v1(z_streamp strm) kaezip_init_ctx(kaezip_ctx); } - return lz_inflateReset(strm); + return Z_OK; } static int kaezip_do_inflate(z_streamp strm, int flush) -- Gitee From f7abfb194b589ff9b6b4267fc8fc0c295be52a95 Mon Sep 17 00:00:00 2001 From: yuzh <1109426275@qq.com> Date: Mon, 28 Apr 2025 09:06:29 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=80=89=E9=A1=B9=EF=BC=8C=E9=83=A8=E5=88=86=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=94=B1zlib=E5=B1=82=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=87=B3kae=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yuzh <1109426275@qq.com> --- KAEZlib/Makefile | 5 ++-- KAEZlib/src/v1/kaezip_deflate.c | 34 +++++++++++++++++++++ KAEZlib/src/v1/kaezip_inflate.c | 52 +++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/KAEZlib/Makefile b/KAEZlib/Makefile index ae09807..ae6955c 100644 --- a/KAEZlib/Makefile +++ b/KAEZlib/Makefile @@ -48,10 +48,11 @@ INCDIR += -I ${WORK_PATH}/src/v2 # Include Libs. LIBDIR += -L/usr/lib64 LIBDIR += -L/usr/local/lib -LIBDIR += -L$(WORK_PATH)/open_source/zlib-1.2.11 +#LIBDIR += -L$(WORK_PATH)/open_source/zlib-1.2.11 LIBDIR += -L$(WORK_PATH)/../kae_build/lib/ #LIBDIR += -L$(WORK_PATH)/open_source/zlib-1.2.7 -LIBS := -lz -lwd -lwd_comp -pthread +#LIBS := -lz -lwd -lwd_comp -pthread +LIBS := -lwd -lwd_comp -pthread LIBS += -lc_nonshared # The flags diff --git a/KAEZlib/src/v1/kaezip_deflate.c b/KAEZlib/src/v1/kaezip_deflate.c index fb5faa4..85a87f4 100644 --- a/KAEZlib/src/v1/kaezip_deflate.c +++ b/KAEZlib/src/v1/kaezip_deflate.c @@ -31,6 +31,8 @@ #include "kaezip_cpucheck.h" #include "kaezip_log.h" +#include "deflate.h" + #define KAEZIP_UPDATE_ZSTREAM_IN(zstrm, in_len) \ do { \ zstrm->next_in += in_len; \ @@ -232,3 +234,35 @@ static int kaezip_do_deflate(z_streamp strm, int flush) return KAEZIP_SUCCESS; } + +unsigned long getDeflateKaezipCtx(z_streamp strm) +{ + deflate_state *state; + + if (strm == Z_NULL) { + return (unsigned long)0; + } + state = (deflate_state *)strm->state; + if (state == Z_NULL) { + return (unsigned long)0; + } + state = (deflate_state *)strm->state; + + return state->kaezip_ctx; +} + +void setDeflateKaezipCtx(z_streamp strm, unsigned long kaezip_ctx) +{ + deflate_state *state; + + if (strm == Z_NULL) { + return; + } + state = (deflate_state *)strm->state; + if (state == Z_NULL) { + return; + } + + state->kaezip_ctx = kaezip_ctx; + return; +} diff --git a/KAEZlib/src/v1/kaezip_inflate.c b/KAEZlib/src/v1/kaezip_inflate.c index cdb31e6..c32e2a8 100644 --- a/KAEZlib/src/v1/kaezip_inflate.c +++ b/KAEZlib/src/v1/kaezip_inflate.c @@ -30,6 +30,10 @@ #include "kaezip_cpucheck.h" #include "kaezip_log.h" +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" + #define KAEZIP_UPDATE_ZSTREAM_IN(zstrm, in_len) \ do { \ zstrm->next_in += in_len; \ @@ -263,3 +267,51 @@ int kz_getAutoInflateAlgType(z_streamp strm) return WCRYPTO_NONE; } +int getInflateStateWrap(z_streamp strm) +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL) { + return 0; + } + state = (struct inflate_state FAR *)strm->state; + + if (state == Z_NULL) { + return 0; + } + + return state->wrap; +} + +unsigned long getInflateKaezipCtx(z_streamp strm) +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL) { + return (unsigned long)0; + } + + state = (struct inflate_state FAR *)strm->state; + if (state == Z_NULL) { + return (unsigned long)0; + } + + return state->kaezip_ctx; +} + +void setInflateKaezipCtx(z_streamp strm, unsigned long kaezip_ctx) +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL) { + return; + } + state = (struct inflate_state FAR *)strm->state; + + if (state == Z_NULL) { + return; + } + + state->kaezip_ctx = kaezip_ctx; + return; +} \ No newline at end of file -- Gitee From d1b8b97c7757e5bbf0471719dc46deb2d48a2ae0 Mon Sep 17 00:00:00 2001 From: yuzh <1109426275@qq.com> Date: Mon, 28 Apr 2025 19:35:20 +0800 Subject: [PATCH 3/3] =?UTF-8?q?KAEZlib=E4=BB=A3=E7=A0=81=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KAEZlib/include/kaezip.h | 2 + KAEZlib/patch/kaezip_for_zlib-1.2.11.patch | 172 ++++++--------------- KAEZlib/setup.sh | 19 ++- 3 files changed, 61 insertions(+), 132 deletions(-) diff --git a/KAEZlib/include/kaezip.h b/KAEZlib/include/kaezip.h index 84e0653..fe4b812 100644 --- a/KAEZlib/include/kaezip.h +++ b/KAEZlib/include/kaezip.h @@ -24,6 +24,8 @@ #define KAEZIP_H #include "zlib.h" +#define Z_CALL_SOFT 10 + #define VERSION_STRUCT_MAXLEN 100 typedef struct { char productName[VERSION_STRUCT_MAXLEN]; diff --git a/KAEZlib/patch/kaezip_for_zlib-1.2.11.patch b/KAEZlib/patch/kaezip_for_zlib-1.2.11.patch index 9b6399c..29f2b47 100644 --- a/KAEZlib/patch/kaezip_for_zlib-1.2.11.patch +++ b/KAEZlib/patch/kaezip_for_zlib-1.2.11.patch @@ -1,6 +1,6 @@ diff -Naru zlib-1.2.11/compress.c zlib-1.2.11_new/compress.c --- zlib-1.2.11/compress.c 2017-01-16 01:29:40.000000000 +0800 -+++ zlib-1.2.11_new/compress.c 2023-06-19 17:23:32.555445560 +0800 ++++ zlib-1.2.11_new/compress.c 2025-04-28 17:14:24.200499160 +0800 @@ -28,7 +28,7 @@ { z_stream stream; @@ -23,8 +23,8 @@ diff -Naru zlib-1.2.11/compress.c zlib-1.2.11_new/compress.c +#endif } diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c ---- zlib-1.2.11/deflate.c 2017-01-16 01:29:40.000000000 +0800 -+++ zlib-1.2.11_new/deflate.c 2023-06-19 17:21:03.747445560 +0800 +--- zlib-1.2.11/deflate.c 2025-04-28 17:07:35.996499160 +0800 ++++ zlib-1.2.11_new/deflate.c 2025-04-28 17:16:11.620499160 +0800 @@ -50,6 +50,7 @@ /* @(#) $Id$ */ @@ -44,7 +44,7 @@ diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c version, stream_size) z_streamp strm; int level; -@@ -344,7 +346,32 @@ +@@ -381,7 +383,37 @@ s->strategy = strategy; s->method = (Byte)method; @@ -65,6 +65,11 @@ diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c +{ +#ifdef CONF_KAEZIP + if (kz_get_devices()) { ++ int ret = lz_deflateInit2_(strm, level, method, windowBits, memLevel, strategy, ++ version, stream_size); ++ if (ret != Z_OK) { ++ return Z_ERRNO; ++ } + return kz_deflateInit2_(strm, level, method, windowBits, memLevel, strategy, + version, stream_size); + } else { @@ -78,7 +83,7 @@ diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c } /* ========================================================================= -@@ -502,7 +529,7 @@ +@@ -539,7 +571,7 @@ } /* ========================================================================= */ @@ -87,7 +92,7 @@ diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c z_streamp strm; { int ret; -@@ -513,6 +540,21 @@ +@@ -550,6 +582,23 @@ return ret; } @@ -97,7 +102,9 @@ diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c +{ +#ifdef CONF_KAEZIP + if (kz_get_devices()) { -+ return kz_deflateReset(strm); ++ int ret = Z_OK; ++ ret = kz_deflateReset(strm); ++ return ret == Z_STREAM_ERROR ? Z_STREAM_ERROR : lz_deflateReset(strm); + } else { + return lz_deflateReset(strm); + } @@ -109,7 +116,7 @@ diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c /* ========================================================================= */ int ZEXPORT deflateSetHeader (strm, head) z_streamp strm; -@@ -653,6 +695,17 @@ +@@ -691,6 +740,17 @@ z_streamp strm; uLong sourceLen; { @@ -127,7 +134,7 @@ diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c deflate_state *s; uLong complen, wraplen; -@@ -760,7 +813,8 @@ +@@ -798,7 +858,8 @@ } while (0) /* ========================================================================= */ @@ -137,7 +144,7 @@ diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c z_streamp strm; int flush; { -@@ -1072,10 +1126,27 @@ +@@ -1110,10 +1171,28 @@ return s->pending != 0 ? Z_OK : Z_STREAM_END; } @@ -147,7 +154,8 @@ diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c +{ +#ifdef CONF_KAEZIP + if (kz_get_devices()) { -+ return kz_deflate(strm, flush); ++ int ret = kz_deflate(strm, flush); ++ return ret == Z_CALL_SOFT ? lz_deflate(strm, flush) : ret; + } else { + return lz_deflate(strm, flush); + } @@ -166,7 +174,7 @@ diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c int status; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; -@@ -1091,9 +1162,24 @@ +@@ -1129,9 +1208,25 @@ ZFREE(strm, strm->state); strm->state = Z_NULL; @@ -179,7 +187,8 @@ diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c +{ +#ifdef CONF_KAEZIP + if (kz_get_devices()) { -+ return kz_deflateEnd(strm); ++ int ret = kz_deflateEnd(strm); ++ return ret == Z_OK ? lz_deflateEnd(strm) : ret; + } else { + return lz_deflateEnd(strm); + } @@ -191,47 +200,10 @@ diff -Naru zlib-1.2.11/deflate.c zlib-1.2.11_new/deflate.c /* ========================================================================= * Copy the source state to the destination state. * To simplify the source, this is not supported for 16-bit MSDOS (which -@@ -2161,3 +2247,36 @@ - FLUSH_BLOCK(s, 0); - return block_done; - } -+ -+unsigned long getDeflateKaezipCtx(z_streamp strm) -+{ -+ deflate_state *state; -+ -+ if (strm == Z_NULL) { -+ return (unsigned long)0; -+ } -+ state = (deflate_state *)strm->state; -+ if (state == Z_NULL) { -+ return (unsigned long)0; -+ } -+ state = (deflate_state *)strm->state; -+ -+ return state->kaezip_ctx; -+} -+ -+void setDeflateKaezipCtx(z_streamp strm, unsigned long kaezip_ctx) -+{ -+ deflate_state *state; -+ -+ if (strm == Z_NULL) { -+ return; -+ } -+ state = (deflate_state *)strm->state; -+ if (state == Z_NULL) { -+ return; -+ } -+ -+ state->kaezip_ctx = kaezip_ctx; -+ return; -+} -+ diff -Naru zlib-1.2.11/deflate.h zlib-1.2.11_new/deflate.h ---- zlib-1.2.11/deflate.h 2017-01-16 01:29:40.000000000 +0800 -+++ zlib-1.2.11_new/deflate.h 2023-06-19 17:21:03.747445560 +0800 -@@ -272,7 +272,7 @@ +--- zlib-1.2.11/deflate.h 2025-04-28 17:07:35.996499160 +0800 ++++ zlib-1.2.11_new/deflate.h 2025-04-28 17:14:24.200499160 +0800 +@@ -267,7 +267,7 @@ * longest match routines access bytes past the input. This is then * updated to the new high water mark. */ @@ -241,8 +213,8 @@ diff -Naru zlib-1.2.11/deflate.h zlib-1.2.11_new/deflate.h /* Output a byte on the stream. diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c ---- zlib-1.2.11/inflate.c 2017-01-16 01:29:40.000000000 +0800 -+++ zlib-1.2.11_new/inflate.c 2023-06-19 17:21:03.747445560 +0800 +--- zlib-1.2.11/inflate.c 2025-04-28 17:07:42.340499160 +0800 ++++ zlib-1.2.11_new/inflate.c 2025-04-28 17:16:41.240499160 +0800 @@ -84,6 +84,7 @@ #include "inftrees.h" #include "inflate.h" @@ -260,7 +232,7 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c z_streamp strm; { struct inflate_state FAR *state; -@@ -154,6 +155,20 @@ +@@ -154,6 +155,21 @@ return inflateResetKeep(strm); } @@ -269,7 +241,8 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c +{ +#ifdef CONF_KAEZIP + if (kz_get_devices()) { -+ return kz_inflateReset(strm); ++ int ret = kz_inflateReset(strm); ++ return ret == Z_OK ? lz_inflateReset(strm) : ret; + } else { + return lz_inflateReset(strm); + } @@ -281,7 +254,7 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c int ZEXPORT inflateReset2(strm, windowBits) z_streamp strm; int windowBits; -@@ -189,10 +204,10 @@ +@@ -189,10 +205,10 @@ /* update state and reset the rest of it */ state->wrap = wrap; state->wbits = (unsigned)windowBits; @@ -294,7 +267,7 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c z_streamp strm; int windowBits; const char *version; -@@ -236,6 +251,23 @@ +@@ -236,6 +252,27 @@ return ret; } @@ -306,6 +279,10 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c +{ +#ifdef CONF_KAEZIP + if (kz_get_devices()) { ++ int ret = lz_inflateInit2_(strm, windowBits, version, stream_size); ++ if (ret != Z_OK) { ++ return Z_ERRNO; ++ } + return kz_inflateInit2_(strm, windowBits, version, stream_size); + } else { + return lz_inflateInit2_(strm, windowBits, version, stream_size); @@ -318,7 +295,7 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c int ZEXPORT inflateInit_(strm, version, stream_size) z_streamp strm; const char *version; -@@ -619,7 +651,8 @@ +@@ -619,7 +656,8 @@ will return Z_BUF_ERROR if it has not reached the end of the stream. */ @@ -328,7 +305,7 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c z_streamp strm; int flush; { -@@ -1273,8 +1306,22 @@ +@@ -1274,8 +1312,23 @@ ret = Z_BUF_ERROR; return ret; } @@ -338,7 +315,8 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c +{ +#ifdef CONF_KAEZIP + if (kz_get_devices()) { -+ return kz_inflate(strm, flush); ++ int ret = kz_inflate(strm, flush); ++ return ret == Z_CALL_SOFT ? lz_inflate(strm, flush) : ret; + } else { + return lz_inflate(strm, flush); + } @@ -352,7 +330,7 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c z_streamp strm; { struct inflate_state FAR *state; -@@ -1285,9 +1332,24 @@ +@@ -1286,9 +1339,25 @@ ZFREE(strm, strm->state); strm->state = Z_NULL; Tracev((stderr, "inflate: end\n")); @@ -365,7 +343,8 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c +{ +#ifdef CONF_KAEZIP + if (kz_get_devices()) { -+ return kz_inflateEnd(strm); ++ int ret = kz_inflateEnd(strm); ++ return ret == Z_OK ? lz_inflateEnd(strm) : ret; + } else { + return lz_inflateEnd(strm); + } @@ -377,7 +356,7 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength) z_streamp strm; Bytef *dictionary; -@@ -1397,6 +1459,7 @@ +@@ -1398,6 +1467,7 @@ return next; } @@ -385,7 +364,7 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c int ZEXPORT inflateSync(strm) z_streamp strm; { -@@ -1434,7 +1497,7 @@ +@@ -1435,7 +1505,7 @@ /* return no joy or set up to restart inflate() on a new block */ if (state->have != 4) return Z_DATA_ERROR; in = strm->total_in; out = strm->total_out; @@ -394,63 +373,9 @@ diff -Naru zlib-1.2.11/inflate.c zlib-1.2.11_new/inflate.c strm->total_in = in; strm->total_out = out; state->mode = TYPE; return Z_OK; -@@ -1559,3 +1622,53 @@ - state = (struct inflate_state FAR *)strm->state; - return (unsigned long)(state->next - state->codes); - } -+ -+int getInflateStateWrap(z_streamp strm) -+{ -+ struct inflate_state FAR *state; -+ -+ if (strm == Z_NULL) { -+ return 0; -+ } -+ state = (struct inflate_state FAR *)strm->state; -+ -+ if (state == Z_NULL) { -+ return 0; -+ } -+ -+ return state->wrap; -+} -+ -+unsigned long getInflateKaezipCtx(z_streamp strm) -+{ -+ struct inflate_state FAR *state; -+ -+ if (strm == Z_NULL) { -+ return (unsigned long)0; -+ } -+ -+ state = (struct inflate_state FAR *)strm->state; -+ if (state == Z_NULL) { -+ return (unsigned long)0; -+ } -+ -+ return state->kaezip_ctx; -+} -+ -+void setInflateKaezipCtx(z_streamp strm, unsigned long kaezip_ctx) -+{ -+ struct inflate_state FAR *state; -+ -+ if (strm == Z_NULL) { -+ return; -+ } -+ state = (struct inflate_state FAR *)strm->state; -+ -+ if (state == Z_NULL) { -+ return; -+ } -+ -+ state->kaezip_ctx = kaezip_ctx; -+ return; -+} -+ diff -Naru zlib-1.2.11/inflate.h zlib-1.2.11_new/inflate.h --- zlib-1.2.11/inflate.h 2017-01-16 01:29:40.000000000 +0800 -+++ zlib-1.2.11_new/inflate.h 2023-06-19 17:21:03.747445560 +0800 ++++ zlib-1.2.11_new/inflate.h 2025-04-28 17:14:24.200499160 +0800 @@ -122,4 +122,5 @@ int sane; /* if false, allow invalid distance too far */ int back; /* bits back of last unprocessed length/lit */ @@ -459,7 +384,7 @@ diff -Naru zlib-1.2.11/inflate.h zlib-1.2.11_new/inflate.h }; diff -Naru zlib-1.2.11/Makefile.in zlib-1.2.11_new/Makefile.in --- zlib-1.2.11/Makefile.in 2017-01-16 01:29:40.000000000 +0800 -+++ zlib-1.2.11_new/Makefile.in 2023-06-19 17:21:03.747445560 +0800 ++++ zlib-1.2.11_new/Makefile.in 2025-04-28 17:14:24.200499160 +0800 @@ -26,7 +26,15 @@ SFLAGS=-O @@ -491,7 +416,7 @@ diff -Naru zlib-1.2.11/Makefile.in zlib-1.2.11_new/Makefile.in $(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS) diff -Naru zlib-1.2.11/uncompr.c zlib-1.2.11_new/uncompr.c --- zlib-1.2.11/uncompr.c 2017-01-16 01:29:40.000000000 +0800 -+++ zlib-1.2.11_new/uncompr.c 2023-06-19 17:24:09.055445560 +0800 ++++ zlib-1.2.11_new/uncompr.c 2025-04-28 17:14:24.200499160 +0800 @@ -32,7 +32,7 @@ { z_stream stream; @@ -500,4 +425,3 @@ diff -Naru zlib-1.2.11/uncompr.c zlib-1.2.11_new/uncompr.c + const uInt max = ((uInt)-1) - 3; // make sure its multiples of 4B uLong len, left; Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */ - diff --git a/KAEZlib/setup.sh b/KAEZlib/setup.sh index 9dc6ca4..b34fa55 100644 --- a/KAEZlib/setup.sh +++ b/KAEZlib/setup.sh @@ -30,8 +30,11 @@ function Target_zlib() rm -rf zlib-1.2.11 tar -zxvf zlib-1.2.11.tar.gz cd "${SRC_PATH}"/open_source/zlib-1.2.11/ - ./configure - make + patch -Np1 < ../../patch/kaezip_for_sec_CVE-2018-25032.patch + patch -Np1 < ../../patch/kaezip_for_sec_CVE-2022-37434.patch + patch -Np1 < ../../patch/kaezip_for_zlib-1.2.11.patch + # ./configure + # make } function Dev_Build_kaezip() @@ -42,9 +45,9 @@ function Dev_Build_kaezip() make clean make cd "${SRC_PATH}"/open_source/zlib-1.2.11/ - patch -Np1 < ../../patch/kaezip_for_sec_CVE-2018-25032.patch - patch -Np1 < ../../patch/kaezip_for_sec_CVE-2022-37434.patch - patch -Np1 < ../../patch/kaezip_for_zlib-1.2.11.patch + # patch -Np1 < ../../patch/kaezip_for_sec_CVE-2018-25032.patch + # patch -Np1 < ../../patch/kaezip_for_sec_CVE-2022-37434.patch + # patch -Np1 < ../../patch/kaezip_for_zlib-1.2.11.patch ./configure --prefix=/usr/local/kaezip make KAEBUILDPATH=${SRC_PATH}/../kae_build KAEZLIBPATH=${SRC_PATH} echo "build zlib success" @@ -60,9 +63,9 @@ function Build_kaezip() make install cd "${SRC_PATH}"/open_source/zlib-1.2.11/ - patch -Np1 < ../../patch/kaezip_for_sec_CVE-2018-25032.patch - patch -Np1 < ../../patch/kaezip_for_sec_CVE-2022-37434.patch - patch -Np1 < ../../patch/kaezip_for_zlib-1.2.11.patch + # patch -Np1 < ../../patch/kaezip_for_sec_CVE-2018-25032.patch + # patch -Np1 < ../../patch/kaezip_for_sec_CVE-2022-37434.patch + # patch -Np1 < ../../patch/kaezip_for_zlib-1.2.11.patch ./configure --prefix=/usr/local/kaezip export LD_LIBRARY_PATH=/usr/local/kaezip/lib:/usr/local/lib:$LD_LIBRARY_PATH make KAEBUILDPATH=${SRC_PATH}/../kae_build KAEZLIBPATH=${SRC_PATH} -- Gitee