Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of improvements #1973

Open
wants to merge 36 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift click to select a range
f11352f
refactor based on develop branch
iliaal Jun 13, 2020
94212a9
redis clone
iliaal Jun 18, 2020
b9713e5
Create new socket on clone
iliaal Jun 19, 2020
e9e47be
Merge branch 'develop' of https://github.com/phpredis/phpredis into r…
iliaal Jul 18, 2020
7c43c54
Added auth support
iliaal Jul 21, 2020
d2c927b
5.3.2
yatsukhnenko Oct 22, 2020
d6458ca
Merge branch 'develop' into redis_clone_develop
iliaal Jan 30, 2021
87297cb
Fixed#1895
defender-11 Jan 22, 2021
270b4db
PHP 8 compatibility Windows
Jan-E Sep 22, 2020
9d0cd31
Prepare 5.3.3 release
michael-grunder Feb 1, 2021
cd05a34
Disable clone handlers for Redis and RedisCluster.
michael-grunder Feb 1, 2021
b50b361
Update changelog for 5.3.3
michael-grunder Feb 1, 2021
9dbd3c5
5.3.2
michael-grunder Feb 1, 2021
edc724e
Pass compression flag when performing HMGET (#1945)
aolley Mar 10, 2021
c48b3a2
Fix ZSTD decompression on bad data.
michael-grunder Feb 26, 2021
fe9011d
Normalize Redis callback prototypes and stop typecasting. (#1935)
michael-grunder Feb 25, 2021
c996ac3
Prepare for 5.3.4 release
michael-grunder Mar 22, 2021
4b13944
Fix PhpRedis session tests to soften timing issues
michael-grunder Mar 23, 2021
d98b9f2
Prepare for 5.3.4 v2
michael-grunder Mar 23, 2021
e67e1a1
More Travis-CI fixes
michael-grunder Mar 23, 2021
e3426c1
5.3.4 - Move the date back one day
michael-grunder Mar 24, 2021
f03092a
Merge branch 'develop' of github.com:phpredis/phpredis into redis_clo…
iliaal May 30, 2021
67a92c5
Merge branch 'redis_clone_develop' into develop_simple_strings
iliaal May 30, 2021
eec2488
fixes
iliaal May 30, 2021
3b67488
merge
iliaal May 30, 2021
d6d53be
Merge branch 'release/5.3.4' of github.com:phpredis/phpredis into dev…
iliaal May 30, 2021
1869069
1st patch
iliaal May 30, 2021
ee32e4d
fixed checks
iliaal May 10, 2020
7c67fc5
fixed checks
iliaal May 10, 2020
5c42e48
Fixed check
iliaal May 10, 2020
357f92e
merge
iliaal May 30, 2021
91ffdd5
Added checks
iliaal May 30, 2021
dac3831
Added lz4 test
iliaal May 31, 2021
1aa5210
removed redundant code
iliaal May 31, 2021
46b76e8
lz4 safety checks
iliaal Aug 9, 2021
d593ad1
refine redis header
iliaal Aug 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 5,58 @@ All changes to phpredis will be documented in this file.
We're basing this format on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and PhpRedis adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [5.3.4] - 2021-03-24 ([GitHub](https://github.com/phpredis/phpredis/releases/5.3.4), [PECL](https:/pecl.php.net/package/redis/5.3.4))

### Sponsors :sparkling_heart:

- [Audiomack](https://audiomack.com)
- [Open LMS](https://openlms.net/)
- [BlueHost](https://bluehost.com)
- [Object Cache Pro for WordPress](https://objectcache.pro/)
- [Avtandil Kikabidze](https://github.com/akalongman)
- [Zaher Ghaibeh](https://github.com/zaherg)
- [BatchLabs](https://batch.com)

### Fixed

- Fix multi/pipeline segfault on Apple silicon [#1917](https://github.com/phpredis/phpredis/issues/1917)
[e0796d48](https://github.com/phpredis/phpredis/commit/e0796d48af18adac2b93982474e7df8de79ec854)
([Michael Grunder](https://github.com/michael-grunder))
- Pass compression flag on HMGET in RedisCluster [#1945](https://github.com/phpredis/phpredis/issues/1945)
[edc724e6](https://github.com/phpredis/phpredis/commit/edc724e6022620414abf4f90256522d03c3160fd)
([Adam Olley](https://github.com/aolley))
- Abide by ZSTD error return constants [#1936](https://github.com/phpredis/phpredis/issues/1936)
[8400ed1c](https://github.com/phpredis/phpredis/pull/1937/commits/8400ed1cb23a22f70727cb60e88ca5397ee10d23)
([Michael Grunder](https://github.com/michael-grunder))
- Fix timing related CI session tests
[9b986bf8](https://github.com/phpredis/phpredis/commit/9b986bf81859f5a5983cd148cb15ee6ce292d288)
([Michael Grunder](https://github.com/michael-grunder))

## [5.3.3] - 2021-02-01 ([GitHub](https://github.com/phpredis/phpredis/releases/5.3.3), [PECL](https:/pecl.php.net/package/redis/5.3.3))

### Sponsors :sparkling_heart:

- [Audiomack](https://audiomack.com)
- [BlueHost](https://bluehost.com)
- [Redis Cache Pro for WordPress](https://wprediscache.com)
- [Avtandil Kikabidze](https://github.com/akalongman)
- [Oleg Babushkin](https://github.com/olbabushkin)
- [Zaher Ghaibeh](https://github.com/zaherg)
- [BatchLabs](https://batch.com)

### Fixed

- Fixed Windows includes for PHP 8
[270b4db8](https://www.github.com/phpredis//phpredis/commit/270b4db821fcbe9fb881eef83e046f87587c4110)
([Jan-E](https://github.com/Jan-E))
- Fix hash_ops for PHP 8.0.1
[87297cbb](https://www.github.com/phpredis/phpredis/commit/87297cbb4000c88b07e729b9379de321ead74aa2)
([defender-11](https://github.com/defender-11))
- Disable clone for Redis and RedisCluster objects. Presently they segfault.
[cd05a344](https://www.github.com/phpredis/phpredis/commit/87297cbb4000c88b07e729b9379de321ead74aa2)
([Michael Grunder](https://github.com/michael-grunder))

## [5.3.2] - 2020-10-22 ([GitHub](https://github.com/phpredis/phpredis/releases/5.3.2), [PECL](https://pecl.php.net/package/redis/5.3.2))

## [5.3.2] - 2020-10-22 ([GitHub](https://github.com/phpredis/phpredis/releases/5.3.2), [PECL](https://pecl.php.net/package/redis/5.3.2))

Expand Down
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,7 @@ You can also make a one-time contribution with one of the links below.
[![Ethereum](https://en.cryptobadges.io/badge/micro/0x43D54E32357B96f68dFF0a6B46976d014Bd603E1)](https://en.cryptobadges.io/donate/0x43D54E32357B96f68dFF0a6B46976d014Bd603E1)

## Sponsors
<a href="https://audiomack.com"><img src="https://styleguide.audiomack.com/styleguide/assets/dl/inline-orange-large.png" alt="Audiomack.com" width="150"></a><a href="https://bluehost.com"><img src="https://upload.wikimedia.org/wikipedia/commons/2/22/Bluehost-logo.png" alt="Bluehost.com" width="150"></a>
<a href="https://audiomack.com"><img src="https://styleguide.audiomack.com/styleguide/assets/dl/inline-orange-large.png" alt="Audiomack.com" width="150"></a><a href="https://bluehost.com"><img src="https://upload.wikimedia.org/wikipedia/commons/2/22/Bluehost-logo.png" alt="Bluehost.com" width="150"></a><a href="https://openlms.net"><img src="https://help.openlms.net/wp-content/uploads/2020/05/cropped-open-lms.png" alt="OpenLMS.net" width="150"></a>

# Table of contents
-----
Expand Down
26 changes: 16 additions & 10 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 73,19 @@ typedef enum _PUBSUB_TYPE {
} PUBSUB_TYPE;

/* options */
#define REDIS_OPT_SERIALIZER 1
#define REDIS_OPT_PREFIX 2
#define REDIS_OPT_READ_TIMEOUT 3
#define REDIS_OPT_SCAN 4
#define REDIS_OPT_FAILOVER 5
#define REDIS_OPT_TCP_KEEPALIVE 6
#define REDIS_OPT_COMPRESSION 7
#define REDIS_OPT_REPLY_LITERAL 8
#define REDIS_OPT_COMPRESSION_LEVEL 9
#define REDIS_OPT_NULL_MBULK_AS_NULL 10
#define REDIS_OPT_SERIALIZER 1
#define REDIS_OPT_PREFIX 2
#define REDIS_OPT_READ_TIMEOUT 3
#define REDIS_OPT_SCAN 4
#define REDIS_OPT_FAILOVER 5
#define REDIS_OPT_TCP_KEEPALIVE 6
#define REDIS_OPT_COMPRESSION 7
#define REDIS_OPT_REPLY_LITERAL 8
#define REDIS_OPT_COMPRESSION_LEVEL 9
#define REDIS_OPT_NULL_MBULK_AS_NULL 10
#define REDIS_OPT_IGBINARY_NO_STRINGS 11
#define REDIS_OPT_COMPRESSION_MIN_SIZE 12
#define REDIS_OPT_COMPRESSION_MIN_RATIO 13

/* cluster options */
#define REDIS_FAILOVER_NONE 0
Expand Down Expand Up @@ -273,8 276,11 @@ typedef struct {
zend_string *persistent_id;

redis_serializer serializer;
int no_strings;
int compression;
int compression_level;
int compression_min_size;
double compression_min_ratio;
long dbNumber;

zend_string *prefix;
Expand Down
55 changes: 45 additions & 10 deletions library.c
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 2162,10 @@ redis_sock_create(char *host, int host_len, int port,

redis_sock->serializer = REDIS_SERIALIZER_NONE;
redis_sock->compression = REDIS_COMPRESSION_NONE;
redis_sock->compression_level = 0; /* default */
redis_sock->no_strings = 0; /* default */
redis_sock->compression_min_size = -1; /* default */
redis_sock->compression_min_ratio = 0; /* default */
redis_sock->mode = ATOMIC;

return redis_sock;
Expand Down Expand Up @@ -2819,6 2823,9 @@ static uint8_t crc8(unsigned char *input, size_t len) {
}
#endif

#define PHP_REDIS_COMPRESSION_RATIO_CHECK(__x) \
(redis_sock->compression_min_ratio > 0 && (((double) __x / (double) len) >= redis_sock->compression_min_ratio))

PHP_REDIS_API int
redis_pack(RedisSock *redis_sock, zval *z, char **val, size_t *val_len)
{
Expand All @@ -2827,7 2834,7 @@ redis_pack(RedisSock *redis_sock, zval *z, char **val, size_t *val_len)
size_t len;

valfree = redis_serialize(redis_sock, z, &buf, &len);
if (redis_sock->compression == REDIS_COMPRESSION_NONE) {
if (redis_sock->compression == REDIS_COMPRESSION_NONE || (redis_sock->compression_min_size > 0 && redis_sock->compression_min_size >= len)) {
*val = buf;
*val_len = len;
return valfree;
Expand All @@ -2845,6 2852,10 @@ redis_pack(RedisSock *redis_sock, zval *z, char **val, size_t *val_len)
size = len MIN(UINT_MAX - len, MAX(LZF_MARGIN, len / 25));
data = emalloc(size);
if ((res = lzf_compress(buf, len, data, size)) > 0) {
if (PHP_REDIS_COMPRESSION_RATIO_CHECK(res)) {
efree(data);
break;
}
if (valfree) efree(buf);
*val = data;
*val_len = res;
Expand Down Expand Up @@ -2876,7 2887,7 @@ redis_pack(RedisSock *redis_sock, zval *z, char **val, size_t *val_len)
size = ZSTD_compressBound(len);
data = emalloc(size);
size = ZSTD_compress(data, size, buf, len, level);
if (!ZSTD_isError(size)) {
if (!ZSTD_isError(size) && !PHP_REDIS_COMPRESSION_RATIO_CHECK(size)) {
if (valfree) efree(buf);
data = erealloc(data, size);
*val = data;
Expand Down Expand Up @@ -2906,9 2917,12 @@ redis_pack(RedisSock *redis_sock, zval *z, char **val, size_t *val_len)
char *lz4buf, *lz4pos;

lz4bound = LZ4_compressBound(len);
lz4buf = emalloc(REDIS_LZ4_HDR_SIZE lz4bound);
lz4buf = emalloc(REDIS_LZ4_HDR_SIZE lz4bound 1);
lz4pos = lz4buf;

/* Added LZ4 header */
*lz4pos = '\4';

/* Copy and move past crc8 length checksum */
memcpy(lz4pos, &crc, sizeof(crc));
lz4pos = sizeof(crc);
Expand All @@ -2923,14 2937,14 @@ redis_pack(RedisSock *redis_sock, zval *z, char **val, size_t *val_len)
lz4len = LZ4_compress_HC(buf, lz4pos, old_len, lz4bound, redis_sock->compression_level);
}

if (lz4len <= 0) {
if (lz4len <= 0 || PHP_REDIS_COMPRESSION_RATIO_CHECK(lz4len)) {
efree(lz4buf);
break;
}

if (valfree) efree(buf);
*val = lz4buf;
*val_len = lz4len REDIS_LZ4_HDR_SIZE;
*val_len = lz4len REDIS_LZ4_HDR_SIZE 1;
return 1;
}
#endif
Expand Down Expand Up @@ -2980,11 2994,16 @@ redis_unpack(RedisSock *redis_sock, const char *val, int val_len, zval *z_ret)
unsigned long long len;

len = ZSTD_getFrameContentSize(val, val_len);
if (
(redis_sock->compression_min_ratio > 0 || redis_sock->compression_min_size > 0)
&& (len == ZSTD_CONTENTSIZE_UNKNOWN || len == ZSTD_CONTENTSIZE_ERROR || len <= 0)
) {
return redis_unserialize(redis_sock, val, val_len, z_ret);
}

if (len != ZSTD_CONTENTSIZE_ERROR && len != ZSTD_CONTENTSIZE_UNKNOWN && len <= INT_MAX)
{
size_t zlen;

data = emalloc(len);
zlen = ZSTD_decompress(data, len, val, val_len);
if (ZSTD_isError(zlen) || zlen != len) {
Expand All @@ -3008,12 3027,18 @@ redis_unpack(RedisSock *redis_sock, const char *val, int val_len, zval *z_ret)

/* We must have at least enough bytes for our header, and can't have more than
* INT_MAX our header size. */
if (val_len < REDIS_LZ4_HDR_SIZE || val_len > INT_MAX REDIS_LZ4_HDR_SIZE)
if (val_len < REDIS_LZ4_HDR_SIZE || val_len > INT_MAX REDIS_LZ4_HDR_SIZE) {
break;
}

/* check bit to ensure payload is LZ4 */
if (*val != '\4') {
break;
}

/* Operate on copies in case our CRC fails */
const char *copy = val;
size_t copylen = val_len;
const char *copy = (val 1);
size_t copylen = val_len - 1;

/* Read in our header bytes */
memcpy(&lz4crc, copy, sizeof(uint8_t));
Expand All @@ -3022,8 3047,9 @@ redis_unpack(RedisSock *redis_sock, const char *val, int val_len, zval *z_ret)
copy = sizeof(int); copylen -= sizeof(int);

/* Make sure our CRC matches (TODO: Maybe issue a docref error?) */
if (crc8((unsigned char*)&datalen, sizeof(datalen)) != lz4crc)
if (crc8((unsigned char*)&datalen, sizeof(datalen)) != lz4crc) {
break;
}

/* Finally attempt decompression */
data = emalloc(datalen);
Expand Down Expand Up @@ -3107,6 3133,11 @@ redis_serialize(RedisSock *redis_sock, zval *z, char **val, size_t *val_len
break;
case REDIS_SERIALIZER_IGBINARY:
#ifdef HAVE_REDIS_IGBINARY
if (Z_TYPE_P(z) == IS_STRING && redis_sock->no_strings) {
*val = Z_STRVAL_P(z);
*val_len = Z_STRLEN_P(z);
return 0;
}
if(igbinary_serialize(&val8, (size_t *)&sz, z) == 0) {
*val = (char*)val8;
*val_len = sz;
Expand Down Expand Up @@ -3178,6 3209,10 @@ redis_unserialize(RedisSock* redis_sock, const char *val, int val_len,
|| (memcmp(val, "\x00\x00\x00\x01", 4) != 0
&& memcmp(val, "\x00\x00\x00\x02", 4) != 0))
{
if (*val != '\0' && redis_sock->no_strings) {
ZVAL_STRINGL(z_ret, val, val_len);
return 1;
}
/* This is most definitely not an igbinary string, so do
not try to unserialize this as one. */
break;
Expand Down
81 changes: 44 additions & 37 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,57 27,37 @@ http://pear.php.net/dtd/package-2.0.xsd">
<email>[email protected]</email>
<active>no</active>
</lead>
<date>2020-10-22</date>
<date>2021-03-24</date>
<version>
<release>5.3.2</release>
<api>5.3.2</api>
<release>5.3.4</release>
<api>5.3.4</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP</license>
<notes>
This release containse some bugfixes and small improvements.
phpredis 5.3.4

This release fixes a multi/pipeline segfault on apple silicon as well as
two small compression related bugs.

You can find a detailed list of changes in Changelog.md and package.xml

* Fix multi/pipeline segfault on Apple silicon [e0796d48] (Michael Grunder)
* Pass compression flag on HMGET in RedisCluster [edc724e6] (Adam Olley)
* Abide by ZSTD error return constants [8400ed1c] (Michael Grunder)
* Fix timing related CI session tests [9b986bf8] (Michael Grunder)

* Sponsors
~ Audiomack - https://audiomack.com
~ Open LMS - https://openlms.net
~ BlueHost - https://bluehost.com
~ Redis Cache Pro for WordPress - https://wprediscache.com
~ Object Cache Pro for WordPress - https://objectcache.pro
~ Avtandil Kikabidze - https://github.com/akalongman
~ Oleg Babushkin - https://github.com/olbabushkin

phpredis 5.3.2

* Use "%.17g" sprintf format for doubles as done in Redis server. [32be3006] (Pavlo Yatsukhnenko)
* Allow to pass NULL as RedisCluster stream context options. [72024afe] (Pavlo Yatsukhnenko)

---

phpredis 5.3.2RC2

---

* Verify SET options are strings before testing them as strings [514bc371] (Michael Grunder)

---

phpredis 5.3.2RC1

---
* Fix cluster segfault when dealing with NULL multi bulk replies in RedisCluster [950e8de8] (Michael Grunder, Alex Offshore)
* Fix xReadGroup() must return message id [500916a4] (Pavlo Yatsukhnenko)
* Fix memory leak in rediscluster session handler [b2cffffc] (Pavlo Yatsukhnenko)
* Fix XInfo() returns false if the stream is empty [5719c9f7, 566fdeeb] (Pavlo Yatsukhnenko, Michael Grunder)
* Relax requirements on set's expire argument [36458071] (Michael Grunder)
* Refactor redis_sock_check_liveness [c5950644] (Pavlo Yatsukhnenko)
* PHP8 compatibility [a7662da7, f4a30cb2, 17848791] (Pavlo Yatsukhnenko, Remi Collet)
* Update documentation [c9ed151d, 398c99d9] (Ali Alwash, Gregoire Pineau)
* Add Redis::OPT_NULL_MULTIBULK_AS_NULL setting to treat NULL multi bulk replies as NULL instead of []. [950e8de8] (Michael Grunder, Alex Offshore)
* Allow to specify stream context for rediscluster session handler [a8daaff8, 4fbe7df7] (Pavlo Yatsukhnenko)
* Add new parameter to RedisCluster to specify stream ssl/tls context. [f771ea16] (Pavlo Yatsukhnenko)
* Add new parameter to RedisSentinel to specify auth information [81c502ae] (Pavlo Yatsukhnenko)
~ Zaher Ghaibeh - https://github.com/zaherg
~ BatchLabs - https://batch.com
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -152,6 132,33 @@ http://pear.php.net/dtd/package-2.0.xsd">
<configureoption name="enable-redis-zstd" prompt="enable zstd compression support?" default="no"/>
</extsrcrelease>
<changelog>
<release>
<stability><release>stable</release><api>stable</api></stability>
<version><release>5.3.3</release><api>5.3.3</api></version>
<date>2021-03-23</date>
<notes>
phpredis 5.3.3

This release mostly includes just small PHP 8 Windows compatibility fixes
such that pecl.php.net can automatically build Windows DLLs.

You can find a detailed list of changes in Changelog.md and package.xml

* Fix PHP8 Windows includes [270b4db8] (Jan-E)
* Fix hash ops for php 8.0.1 [87297cbb] (defender-11)
* Disable cloning Redis and RedisCluster objects [cd05a344]
(Michael Grunder)

* Sponsors
~ Audiomack - https://audiomack.com
~ BlueHost - https://bluehost.com
~ Redis Cache Pro for WordPress - https://wprediscache.com
~ Avtandil Kikabidze - https://github.com/akalongman
~ Zaher Ghaibeh - https://github.com/zaherg
~ BatchLabs - https://batch.com
</notes>
</release>

<release>
<stability><release>stable</release><api>stable</api></stability>
<version><release>5.3.2</release><api>5.3.2</api></version>
Expand Down
2 changes: 1 addition & 1 deletion php_redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 23,7 @@
#define PHP_REDIS_H

/* phpredis version */
#define PHP_REDIS_VERSION "5.3.2"
#define PHP_REDIS_VERSION "5.3.4"

PHP_METHOD(Redis, __construct);
PHP_METHOD(Redis, __destruct);
Expand Down
Loading