Unverified Commit 737a0905 authored by guybe7's avatar guybe7 Committed by GitHub
Browse files

Set errno in case XADD with partial ID fails (#11424)

This is a rare failure mode of a new feature of redis 7 introduced in #9217
(when the incremental part of the ID overflows).
Till now, the outcome of that error was undetermined (could easily result in
`Elements are too large to be stored` wrongly, due to unset `errno`).
parent bd23b15a
...@@ -437,6 +437,7 @@ int streamAppendItem(stream *s, robj **argv, int64_t numfields, streamID *added_ ...@@ -437,6 +437,7 @@ int streamAppendItem(stream *s, robj **argv, int64_t numfields, streamID *added_
* in time. */ * in time. */
if (s->last_id.ms == use_id->ms) { if (s->last_id.ms == use_id->ms) {
if (s->last_id.seq == UINT64_MAX) { if (s->last_id.seq == UINT64_MAX) {
errno = EDOM;
return C_ERR; return C_ERR;
} }
id = s->last_id; id = s->last_id;
...@@ -2025,10 +2026,12 @@ void xaddCommand(client *c) { ...@@ -2025,10 +2026,12 @@ void xaddCommand(client *c) {
} }
/* Append using the low level function and return the ID. */ /* Append using the low level function and return the ID. */
errno = 0;
streamID id; streamID id;
if (streamAppendItem(s,c->argv+field_pos,(c->argc-field_pos)/2, if (streamAppendItem(s,c->argv+field_pos,(c->argc-field_pos)/2,
&id,parsed_args.id_given ? &parsed_args.id : NULL,parsed_args.seq_given) == C_ERR) &id,parsed_args.id_given ? &parsed_args.id : NULL,parsed_args.seq_given) == C_ERR)
{ {
serverAssert(errno != 0);
if (errno == EDOM) if (errno == EDOM)
addReplyError(c,"The ID specified in XADD is equal or smaller than " addReplyError(c,"The ID specified in XADD is equal or smaller than "
"the target stream top item"); "the target stream top item");
......
...@@ -882,6 +882,12 @@ start_server {tags {"stream"}} { ...@@ -882,6 +882,12 @@ start_server {tags {"stream"}} {
set reply [r XINFO STREAM x FULL] set reply [r XINFO STREAM x FULL]
assert_equal [dict get $reply max-deleted-entry-id] "2-0" assert_equal [dict get $reply max-deleted-entry-id] "2-0"
} }
test {XADD with artial ID with maximal seq} {
r DEL x
r XADD x 1-18446744073709551615 f1 v1
assert_error {*The ID specified in XADD is equal or smaller*} {r XADD x 1-* f2 v2}
}
} }
start_server {tags {"stream needs:debug"} overrides {appendonly yes aof-use-rdb-preamble no}} { start_server {tags {"stream needs:debug"} overrides {appendonly yes aof-use-rdb-preamble no}} {
......
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