Unverified Commit 6476c8e8 authored by ZhaolongLi's avatar ZhaolongLi Committed by GitHub
Browse files

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: default avatarlizhaolong.lzl <lizhaolong.lzl@B-54MPMD6R-0221.local>
Co-authored-by: default avatarOran Agra <oran@redislabs.com>
Co-authored-by: default avatarguybe7 <guy.benoish@redislabs.com>
parent 74fe15b3
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment