Skip to content

Commit

Permalink
box: fix empty tuple invalid update
Browse files Browse the repository at this point in the history
The tuple:update() used to work incorrectly in case of empty
tuple produced with box.tuple.new{} because update_create_rope
unconditionally initialized a new rope with [tuple_data,
mp_next(tuple_data)] field that might not exists.

Closes #4041
  • Loading branch information
kshcherbatov authored and kyukhin committed Apr 23, 2019
1 parent 5e0ee71 commit 3eac590
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/box/tuple_update.c
Expand Up @@ -834,6 +834,8 @@ update_create_rope(struct tuple_update *update, const char *tuple_data,
return -1;
const char *field = tuple_data;
const char *end = tuple_data_end;
if (field == end)
return 0;

/* Add first field to rope */
mp_next(&tuple_data);
Expand Down
21 changes: 21 additions & 0 deletions test/box/tuple.result
Expand Up @@ -859,6 +859,27 @@ t
t = nil
---
...
--
-- gh-4041: Invalid field on empty tuple update.
--
t = box.tuple.new{}
---
...
t:update({{'=', 1, 1}})
---
- [1]
...
t:upsert({{'=', 1, 1}})
---
- [1]
...
t:update({{'+', 1, 1}})
---
- error: Field 1 was not found in the tuple
...
t = nil
---
...
--------------------------------------------------------------------------------
-- test msgpack.encode + tuple
--------------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions test/box/tuple.test.lua
Expand Up @@ -270,6 +270,16 @@ t = box.tuple.new(require('yaml').decode("[17711728, {1000: 'xxx'}]"))
t:update({{'=', 2, t[2]}})
t
t = nil

--
-- gh-4041: Invalid field on empty tuple update.
--
t = box.tuple.new{}
t:update({{'=', 1, 1}})
t:upsert({{'=', 1, 1}})
t:update({{'+', 1, 1}})
t = nil

--------------------------------------------------------------------------------
-- test msgpack.encode + tuple
--------------------------------------------------------------------------------
Expand Down

0 comments on commit 3eac590

Please sign in to comment.