From 0753bec3b137c6ccbbdaa5bce7425c7a1860a901 Mon Sep 17 00:00:00 2001 From: Dick Tang Date: Fri, 10 Jun 2016 11:30:42 +0800 Subject: [PATCH 1/3] correct the compression_factor calculation --- php_memcached.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/php_memcached.c b/php_memcached.c index cf26bff6..38aabd33 100644 --- a/php_memcached.c +++ b/php_memcached.c @@ -108,10 +108,10 @@ static int php_memc_list_entry(void) { #define MEMC_VAL_COMPRESSION_ZLIB (1<<1) #define MEMC_VAL_COMPRESSION_FASTLZ (1<<2) -#define MEMC_VAL_GET_FLAGS(internal_flags) ((internal_flags & MEMC_MASK_INTERNAL) >> 4) -#define MEMC_VAL_SET_FLAG(internal_flags, internal_flag) ((internal_flags) |= ((internal_flag << 4) & MEMC_MASK_INTERNAL)) -#define MEMC_VAL_HAS_FLAG(internal_flags, internal_flag) ((MEMC_VAL_GET_FLAGS(internal_flags) & internal_flag) == internal_flag) -#define MEMC_VAL_DEL_FLAG(internal_flags, internal_flag) internal_flags &= ~((internal_flag << 4) & MEMC_MASK_INTERNAL) +#define MEMC_VAL_GET_FLAGS(internal_flags) (((internal_flags) & MEMC_MASK_INTERNAL) >> 4) +#define MEMC_VAL_SET_FLAG(internal_flags, internal_flag) ((internal_flags) |= (((internal_flag) << 4) & MEMC_MASK_INTERNAL)) +#define MEMC_VAL_HAS_FLAG(internal_flags, internal_flag) ((MEMC_VAL_GET_FLAGS(internal_flags) & (internal_flag)) == (internal_flag)) +#define MEMC_VAL_DEL_FLAG(internal_flags, internal_flag) (internal_flags &= (~(((internal_flag) << 4) & MEMC_MASK_INTERNAL))) /**************************************** User-defined flags @@ -867,7 +867,7 @@ zend_bool s_compress_value (php_memc_compression_type compression_type, zend_str } /* This means the value was too small to be compressed, still a success */ - if (compressed_size > (ZSTR_LEN(payload) * MEMC_G(compression_factor))) { + if (ZSTR_LEN(payload) < (compressed_size * MEMC_G(compression_factor))) { efree (buffer); return 1; } From 3a2e9a1c628fd01660957ecdfd7a3f20944ee4a9 Mon Sep 17 00:00:00 2001 From: Dick Tang Date: Tue, 24 Jan 2017 13:42:05 +0800 Subject: [PATCH 2/3] send uncompress value and proper set compressed flags when compression saving is too small --- php_memcached.c | 1 + 1 file changed, 1 insertion(+) diff --git a/php_memcached.c b/php_memcached.c index 38aabd33..7494986a 100644 --- a/php_memcached.c +++ b/php_memcached.c @@ -868,6 +868,7 @@ zend_bool s_compress_value (php_memc_compression_type compression_type, zend_str /* This means the value was too small to be compressed, still a success */ if (ZSTR_LEN(payload) < (compressed_size * MEMC_G(compression_factor))) { + MEMC_VAL_DEL_FLAG(*flags, MEMC_VAL_COMPRESSION_FASTLZ | MEMC_VAL_COMPRESSION_ZLIB); efree (buffer); return 1; } From ad8a916ed002ede0517a32c6582740ea123fa541 Mon Sep 17 00:00:00 2001 From: Dick Tang Date: Wed, 25 Jan 2017 01:54:41 +0800 Subject: [PATCH 3/3] fix the inequality of the compression condition --- php_memcached.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php_memcached.c b/php_memcached.c index 7494986a..714d7bb2 100644 --- a/php_memcached.c +++ b/php_memcached.c @@ -867,7 +867,7 @@ zend_bool s_compress_value (php_memc_compression_type compression_type, zend_str } /* This means the value was too small to be compressed, still a success */ - if (ZSTR_LEN(payload) < (compressed_size * MEMC_G(compression_factor))) { + if (ZSTR_LEN(payload) <= (compressed_size * MEMC_G(compression_factor))) { MEMC_VAL_DEL_FLAG(*flags, MEMC_VAL_COMPRESSION_FASTLZ | MEMC_VAL_COMPRESSION_ZLIB); efree (buffer); return 1;