fix(server): Fix hset buffer bug (#994)

Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
This commit is contained in:
Vladislav 2023-03-26 12:53:09 +03:00 committed by GitHub
parent 72f67eddd8
commit 0c83b09aea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -1101,15 +1101,15 @@ StringMap* HSetFamily::ConvertToStrMap(uint8_t* lp) {
sm->Reserve(lplen / 2);
uint8_t* lp_elem = lpFirst(lp);
uint8_t intbuf[LP_INTBUF_SIZE];
uint8_t intbuf[2][LP_INTBUF_SIZE];
DCHECK(lp_elem); // empty containers are not allowed.
do {
string_view key = LpGetView(lp_elem, intbuf);
string_view key = LpGetView(lp_elem, intbuf[0]);
lp_elem = lpNext(lp, lp_elem); // switch to value
DCHECK(lp_elem);
string_view value = LpGetView(lp_elem, intbuf);
string_view value = LpGetView(lp_elem, intbuf[1]);
lp_elem = lpNext(lp, lp_elem); // switch to next key
CHECK(sm->AddOrUpdate(key, value)); // must be unique
} while (lp_elem);

View file

@ -215,4 +215,14 @@ TEST_F(HSetFamilyTest, HSetEx) {
EXPECT_THAT(Run({"HGET", "k", "f"}), ArgType(RespExpr::NIL));
}
TEST_F(HSetFamilyTest, TriggerConvertToStrMap) {
const int kElements = 200;
// Enough for IsGoodForListpack to become false
for (size_t i = 0; i < kElements; i++) {
auto k = absl::StrCat(100500700u + i);
Run({"HSET", "hk", k, "100500700"});
}
EXPECT_THAT(Run({"HLEN", "hk"}), IntArg(kElements));
}
} // namespace dfly