valkey-io/valkey

[BUG] A large negative number(e.g. -LONG_MAX) in HRANDFIELD/ZRANDMEMBER can easily cause Valkey to crash.

已關閉

#844 建立於 2024年7月30日

 (18 則留言) (1 個反應) (1 位負責人)C (1,138 個分叉)batch import
good first issuehelp wanted

倉庫指標

星標
 (25,779 顆星)
PR 合併指標
 (平均合併 17天 7小時) (30 天內合併 74 個 PR)

描述

Describe the bug

When using the HRANDFIELD or ZRANDMEMBER commands, if an extremely negative value(e.g. -LONG_MAX) is provided, the memory will continue to rise and eventually cause Redis to crash.

To reproduce

HRANDFIELD hash -9223372036854775807

Expected behavior

IMHO, it is more reasonable to set a limit on count according to the memory limit or the actual size of the hash table to prevent Redis from crashing. This can prevent crashes caused by careless and incorrect use. If a user really needs to sample a lot of elements that allow duplicates, he can achieve the same purpose by calling the command multiple times.

貢獻者指南