Unverified Commit 6461f09f authored by Vitaly's avatar Vitaly Committed by GitHub
Browse files

Fix ZRANGESTORE crash when zset_max_listpack_entries is 0 (#10767)

When `zrangestore` is called container destination object is created. 
Before this PR we used to create a listpack based object even if `zset-max-ziplist-entries`
or equivalent`zset-max-listpack-entries` was set to 0.
This triggered immediate conversion of the listpack into a skiplist in `zrangestore`, which hits
an assertion resulting in an engine crash.

Added a TCL test that reproduces this issue.
parent 2a099d49
...@@ -1186,9 +1186,10 @@ void zsetConvert(robj *zobj, int encoding) { ...@@ -1186,9 +1186,10 @@ void zsetConvert(robj *zobj, int encoding) {
zs->zsl = zslCreate(); zs->zsl = zslCreate();
eptr = lpSeek(zl,0); eptr = lpSeek(zl,0);
serverAssertWithInfo(NULL,zobj,eptr != NULL); if (eptr != NULL) {
sptr = lpNext(zl,eptr); sptr = lpNext(zl,eptr);
serverAssertWithInfo(NULL,zobj,sptr != NULL); serverAssertWithInfo(NULL,zobj,sptr != NULL);
}
while (eptr != NULL) { while (eptr != NULL) {
score = zzlGetScore(sptr); score = zzlGetScore(sptr);
......
...@@ -2208,6 +2208,15 @@ start_server {tags {"zset"}} { ...@@ -2208,6 +2208,15 @@ start_server {tags {"zset"}} {
assert_match "*syntax*" $err assert_match "*syntax*" $err
} }
test {ZRANGESTORE with zset-max-listpack-entries 0 dst key should use skiplist encoding} {
set original_max [lindex [r config get zset-max-listpack-entries] 1]
r config set zset-max-listpack-entries 0
r del z1{t} z2{t}
r zadd z1{t} 1 a
assert_equal 1 [r zrangestore z2{t} z1{t} 0 -1]
r config set zset-max-listpack-entries $original_max
}
test {ZRANGE invalid syntax} { test {ZRANGE invalid syntax} {
catch {r zrange z1{t} 0 -1 limit 1 2} err catch {r zrange z1{t} 0 -1 limit 1 2} err
assert_match "*syntax*" $err assert_match "*syntax*" $err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment