mirror of
https://github.com/redis/redis.git
synced 2026-04-21 03:01:35 -04:00
Fix range issues in default value of LIMIT argument to XADD and XTRIM (#9147)
This seems to be an unimportant bug that was accidentally generated. If the user does not specify limit in streamParseAddOrTrimArgsOrReply, the initial value of args->limit is 100 * server.stream_node_max_entries, which may lead to out of bounds, and then the default function of limit in xadd becomes invalid (this failure occurs in streamTrim). Additionally, provide sane default for args->limit in case stream_node_max_entries is set to 0. Co-authored-by: lizhaolong.lzl <lizhaolong.lzl@B-54MPMD6R-0221.local> Co-authored-by: Oran Agra <oran@redislabs.com> Co-authored-by: guybe7 <guy.benoish@redislabs.com>
This commit is contained in:
@@ -982,11 +982,15 @@ static int streamParseAddOrTrimArgsOrReply(client *c, streamAddTrimArgs *args, i
|
||||
}
|
||||
} else {
|
||||
/* User didn't provide LIMIT, we must set it. */
|
||||
|
||||
if (args->approx_trim) {
|
||||
/* In order to prevent from trimming to do too much work and cause
|
||||
* latency spikes we limit the amount of work it can do */
|
||||
/* In order to prevent from trimming to do too much work and
|
||||
* cause latency spikes we limit the amount of work it can do.
|
||||
* We have to cap args->limit from both sides in case
|
||||
* stream_node_max_entries is 0 or too big (could cause overflow)
|
||||
*/
|
||||
args->limit = 100 * server.stream_node_max_entries; /* Maximum 100 rax nodes. */
|
||||
if (args->limit <= 0) args->limit = 10000;
|
||||
if (args->limit > 1000000) args->limit = 1000000;
|
||||
} else {
|
||||
/* No LIMIT for exact trimming */
|
||||
args->limit = 0;
|
||||
|
||||
Reference in New Issue
Block a user