valkey-io/valkey

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

オープン

#844 opened on 2024/07/30

 (18 件のコメント) (1 件のリアクション) (1 人の担当者)C (1,138 件のフォーク)batch import
good first issuehelp wanted

Repository metrics

Stars
 (25,779 個のスター)
PR merge metrics
 (平均マージ 17d 7h) (30d で 74 merged PRs)

説明

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.

コントリビューターガイド