mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 18:05:44 +02:00
fix: crash during SORT DESC call (#3637)
fixes #3636 The problem was that instead of implementing GT operator, we implemented !LT, which is GE operator. As a result the iterators inside the sort algorithm reached out of bounds. --------- Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
2c32e5085c
commit
67117ff081
2 changed files with 13 additions and 3 deletions
|
@ -1184,9 +1184,10 @@ void GenericFamily::Sort(CmdArgList args, ConnectionContext* cntx) {
|
|||
});
|
||||
} else {
|
||||
std::sort(entries.begin(), entries.end(),
|
||||
[reversed, &entries](const auto& lhs, const auto& rhs) {
|
||||
DCHECK(&rhs < &(*entries.end()) && &rhs >= &(*entries.begin()));
|
||||
return bool(lhs.Cmp() < rhs.Cmp()) ^ reversed;
|
||||
[reversed, &entries](const auto& lhs, const auto& rhs) -> bool {
|
||||
DCHECK((&rhs - entries.data()) >= 0);
|
||||
DCHECK((&rhs - entries.data()) < int64_t(entries.size()));
|
||||
return reversed ? rhs.Cmp() < lhs.Cmp() : lhs.Cmp() < rhs.Cmp();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -481,6 +481,15 @@ TEST_F(GenericFamilyTest, Sort) {
|
|||
;
|
||||
}
|
||||
|
||||
TEST_F(GenericFamilyTest, SortBug3636) {
|
||||
Run({"RPUSH", "foo", "1.100000023841858", "1.100000023841858", "1.100000023841858", "-15710",
|
||||
"1.100000023841858", "1.100000023841858", "1.100000023841858", "-15710", "-15710",
|
||||
"1.100000023841858", "-15710", "-15710", "-15710", "-15710", "1.100000023841858", "-15710",
|
||||
"-15710"});
|
||||
auto resp = Run({"SORT", "foo", "desc", "alpha"});
|
||||
ASSERT_THAT(resp, ArrLen(17));
|
||||
}
|
||||
|
||||
TEST_F(GenericFamilyTest, TimeNoKeys) {
|
||||
auto resp = Run({"time"});
|
||||
EXPECT_THAT(resp, ArrLen(2));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue