Skip to content

Commit d211662

Browse files
authored
fix: ZRANGE with LIMIT parameters crash fixed (#4944)
fixed: #4943
1 parent 9505d21 commit d211662

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/server/container_utils.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ bool IterateSortedSet(const detail::RobjWrapper* robj_wrapper, const IterateSort
217217
if (end < 0 || unsigned(end) >= llen)
218218
end = llen - 1;
219219

220+
if (start > end || unsigned(start) >= llen)
221+
return true;
222+
220223
unsigned rangelen = unsigned(end - start) + 1;
221224

222225
if (robj_wrapper->encoding() == OBJ_ENCODING_LISTPACK) {

src/server/zset_family_test.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,4 +1212,10 @@ TEST_F(ZSetFamilyTest, RangeStore) {
12121212
EXPECT_THAT(resp, ArrLen(0));
12131213
}
12141214

1215+
TEST_F(ZSetFamilyTest, ZRangeZeroElements) {
1216+
Run({"zadd", "myzset", "1", "one"});
1217+
auto resp = Run({"ZRANGE", "myzset", "0", "-1", "LIMIT", "2", "10"});
1218+
ASSERT_THAT(resp, ArrLen(0));
1219+
}
1220+
12151221
} // namespace dfly

0 commit comments

Comments
 (0)