Commit fd7bde57 authored by Vitaly's avatar Vitaly Committed by Oran Agra
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.

(cherry picked from commit 6461f09f)
parent 9d40f1cb
...@@ -1192,9 +1192,10 @@ void zsetConvert(robj *zobj, int encoding) { ...@@ -1192,9 +1192,10 @@ void zsetConvert(robj *zobj, int encoding) {
zs->zsl = zslCreate(); zs->zsl = zslCreate();
eptr = ziplistIndex(zl,0); eptr = ziplistIndex(zl,0);
serverAssertWithInfo(NULL,zobj,eptr != NULL); if (eptr != NULL) {
sptr = ziplistNext(zl,eptr); sptr = ziplistNext(zl,eptr);
serverAssertWithInfo(NULL,zobj,sptr != NULL); serverAssertWithInfo(NULL,zobj,sptr != NULL);
}
while (eptr != NULL) { while (eptr != NULL) {
score = zzlGetScore(sptr); score = zzlGetScore(sptr);
......
...@@ -1643,6 +1643,15 @@ start_server {tags {"zset"}} { ...@@ -1643,6 +1643,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-ziplist-entries] 1]
r config set zset-max-ziplist-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-ziplist-entries $original_max
}
test {ZRANGE invalid syntax} { test {ZRANGE invalid syntax} {
catch {r zrange z1 0 -1 limit 1 2} err catch {r zrange z1 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