From 8456663a8cefdb8b923de7f7b69c58a948811beb Mon Sep 17 00:00:00 2001 From: kjdev Date: Fri, 15 Aug 2025 12:01:04 +0900 Subject: [PATCH 1/2] fix: disable dcz encoding when dictionary loading fails --- zstd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zstd.c b/zstd.c index 6623573..3e498c9 100644 --- a/zstd.c +++ b/zstd.c @@ -1298,6 +1298,7 @@ php_zstd_output_handler_load_dict(php_zstd_context *ctx) char *dict = PHP_ZSTD_G(output_compression_dict); if (!dict || strlen(dict) <= 0) { + PHP_ZSTD_G(compression_coding) &= ~PHP_ZSTD_ENCODING_DCZ; return NULL; } @@ -1307,6 +1308,7 @@ php_zstd_output_handler_load_dict(php_zstd_context *ctx) NULL, context); if (!stream) { ZSTD_WARNING("could not open dictionary stream: %s", dict); + PHP_ZSTD_G(compression_coding) &= ~PHP_ZSTD_ENCODING_DCZ; return NULL; } @@ -1320,6 +1322,7 @@ php_zstd_output_handler_load_dict(php_zstd_context *ctx) php_stream_close(stream); if (!data) { + PHP_ZSTD_G(compression_coding) &= ~PHP_ZSTD_ENCODING_DCZ; return NULL; } From 229de9159c12b987b7be1ad03ec7ab1991a1d187 Mon Sep 17 00:00:00 2001 From: kjdev Date: Fri, 15 Aug 2025 12:03:21 +0900 Subject: [PATCH 2/2] test: add dcz output handler when dictionary loading fails --- tests/ob_dcz_005.phpt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/ob_dcz_005.phpt diff --git a/tests/ob_dcz_005.phpt b/tests/ob_dcz_005.phpt new file mode 100644 index 0000000..f942e7d --- /dev/null +++ b/tests/ob_dcz_005.phpt @@ -0,0 +1,24 @@ +--TEST-- +output handler: dcz +--SKIPIF-- + +--GET-- +ob=dictionary +--ENV-- +HTTP_ACCEPT_ENCODING=zstd,dcz +HTTP_AVAILABLE_DICTIONARY=:5wg7BLZeirApJAxOdI/QBi8RvwZuIJfPf0TwMo/x/yg=: +--FILE-- + +--EXPECT_EXTERNAL-- +files/ob_data.zstd +--EXPECTHEADERS-- +Content-Encoding: zstd +Vary: Accept-Encoding