* [tarantool-patches] [PATCH v1 1/1] box: fix empty tuple invalid update
@ 2019-04-23 8:17 Kirill Shcherbatov
2019-04-23 10:11 ` [tarantool-patches] " Vladislav Shpilevoy
2019-04-23 10:30 ` Kirill Yukhin
0 siblings, 2 replies; 5+ messages in thread
From: Kirill Shcherbatov @ 2019-04-23 8:17 UTC (permalink / raw)
To: tarantool-patches, v.shpilevoy; +Cc: Kirill Shcherbatov
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
---
http://github.com/tarantool/tarantool/tree/kshch/gh-4041-empty-tuple-update
https://github.com/tarantool/tarantool/issues/4041
src/box/tuple_update.c | 2 ++
test/box/tuple.result | 21 +++++++++++++++++++++
test/box/tuple.test.lua | 10 ++++++++++
3 files changed, 33 insertions(+)
diff --git a/src/box/tuple_update.c b/src/box/tuple_update.c
index 01c55fb1a..849073258 100644
--- a/src/box/tuple_update.c
+++ b/src/box/tuple_update.c
@@ -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);
diff --git a/test/box/tuple.result b/test/box/tuple.result
index 82ad8404d..2561ebc35 100644
--- a/test/box/tuple.result
+++ b/test/box/tuple.result
@@ -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
--------------------------------------------------------------------------------
diff --git a/test/box/tuple.test.lua b/test/box/tuple.test.lua
index 8030b0884..b0a4ab173 100644
--- a/test/box/tuple.test.lua
+++ b/test/box/tuple.test.lua
@@ -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
--------------------------------------------------------------------------------
--
2.21.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tarantool-patches] Re: [PATCH v1 1/1] box: fix empty tuple invalid update
2019-04-23 8:17 [tarantool-patches] [PATCH v1 1/1] box: fix empty tuple invalid update Kirill Shcherbatov
@ 2019-04-23 10:11 ` Vladislav Shpilevoy
2019-04-23 10:17 ` Kirill Shcherbatov
2019-04-23 10:30 ` Kirill Yukhin
1 sibling, 1 reply; 5+ messages in thread
From: Vladislav Shpilevoy @ 2019-04-23 10:11 UTC (permalink / raw)
To: Kirill Shcherbatov, tarantool-patches
Hi! Thanks for the patch!
On 23/04/2019 11:17, Kirill Shcherbatov wrote:
> 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
> ---
> http://github.com/tarantool/tarantool/tree/kshch/gh-4041-empty-tuple-update
> https://github.com/tarantool/tarantool/issues/4041
>
> src/box/tuple_update.c | 2 ++
> test/box/tuple.result | 21 +++++++++++++++++++++
> test/box/tuple.test.lua | 10 ++++++++++
> 3 files changed, 33 insertions(+)
>
> diff --git a/src/box/tuple_update.c b/src/box/tuple_update.c
> index 01c55fb1a..849073258 100644
> --- a/src/box/tuple_update.c
> +++ b/src/box/tuple_update.c
> @@ -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;
A few lines above you allocate struct update_field, which
is unused when field == end. Please, move this check before
update->alloc().
>
> /* Add first field to rope */
> mp_next(&tuple_data);
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tarantool-patches] Re: [PATCH v1 1/1] box: fix empty tuple invalid update
2019-04-23 10:11 ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-04-23 10:17 ` Kirill Shcherbatov
2019-04-23 10:20 ` Vladislav Shpilevoy
0 siblings, 1 reply; 5+ messages in thread
From: Kirill Shcherbatov @ 2019-04-23 10:17 UTC (permalink / raw)
To: tarantool-patches, Vladislav Shpilevoy
> A few lines above you allocate struct update_field, which
> is unused when field == end. Please, move this check before
> update->alloc().
You are right. Thank you.
====================================
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
---
src/box/tuple_update.c | 3 +++
test/box/tuple.result | 21 +++++++++++++++++++++
test/box/tuple.test.lua | 10 ++++++++++
3 files changed, 34 insertions(+)
diff --git a/src/box/tuple_update.c b/src/box/tuple_update.c
index 01c55fb1a..b879d50f9 100644
--- a/src/box/tuple_update.c
+++ b/src/box/tuple_update.c
@@ -826,6 +826,9 @@ update_create_rope(struct tuple_update *update, const char *tuple_data,
region_alloc_free_stub, update->alloc_ctx);
if (update->rope == NULL)
return -1;
+ if (tuple_data == tuple_data_end)
+ return 0;
+
/* Initialize the rope with the old tuple. */
struct update_field *first = (struct update_field *)
diff --git a/test/box/tuple.result b/test/box/tuple.result
index 82ad8404d..2561ebc35 100644
--- a/test/box/tuple.result
+++ b/test/box/tuple.result
@@ -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
--------------------------------------------------------------------------------
diff --git a/test/box/tuple.test.lua b/test/box/tuple.test.lua
index 8030b0884..b0a4ab173 100644
--- a/test/box/tuple.test.lua
+++ b/test/box/tuple.test.lua
@@ -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
--------------------------------------------------------------------------------
--
2.21.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tarantool-patches] Re: [PATCH v1 1/1] box: fix empty tuple invalid update
2019-04-23 10:17 ` Kirill Shcherbatov
@ 2019-04-23 10:20 ` Vladislav Shpilevoy
0 siblings, 0 replies; 5+ messages in thread
From: Vladislav Shpilevoy @ 2019-04-23 10:20 UTC (permalink / raw)
To: Kirill Shcherbatov, tarantool-patches, Kirill Yukhin
LGTM.
On 23/04/2019 13:17, Kirill Shcherbatov wrote:
> > A few lines above you allocate struct update_field, which
>> is unused when field == end. Please, move this check before
>> update->alloc().
> You are right. Thank you.
> ====================================
> 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
> ---
> src/box/tuple_update.c | 3 +++
> test/box/tuple.result | 21 +++++++++++++++++++++
> test/box/tuple.test.lua | 10 ++++++++++
> 3 files changed, 34 insertions(+)
>
> diff --git a/src/box/tuple_update.c b/src/box/tuple_update.c
> index 01c55fb1a..b879d50f9 100644
> --- a/src/box/tuple_update.c
> +++ b/src/box/tuple_update.c
> @@ -826,6 +826,9 @@ update_create_rope(struct tuple_update *update, const char *tuple_data,
> region_alloc_free_stub, update->alloc_ctx);
> if (update->rope == NULL)
> return -1;
> + if (tuple_data == tuple_data_end)
> + return 0;
> +
> /* Initialize the rope with the old tuple. */
>
> struct update_field *first = (struct update_field *)
> diff --git a/test/box/tuple.result b/test/box/tuple.result
> index 82ad8404d..2561ebc35 100644
> --- a/test/box/tuple.result
> +++ b/test/box/tuple.result
> @@ -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
> --------------------------------------------------------------------------------
> diff --git a/test/box/tuple.test.lua b/test/box/tuple.test.lua
> index 8030b0884..b0a4ab173 100644
> --- a/test/box/tuple.test.lua
> +++ b/test/box/tuple.test.lua
> @@ -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
> --------------------------------------------------------------------------------
> --
> 2.21.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tarantool-patches] Re: [PATCH v1 1/1] box: fix empty tuple invalid update
2019-04-23 8:17 [tarantool-patches] [PATCH v1 1/1] box: fix empty tuple invalid update Kirill Shcherbatov
2019-04-23 10:11 ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-04-23 10:30 ` Kirill Yukhin
1 sibling, 0 replies; 5+ messages in thread
From: Kirill Yukhin @ 2019-04-23 10:30 UTC (permalink / raw)
To: tarantool-patches; +Cc: v.shpilevoy, Kirill Shcherbatov
Hello,
On 23 Apr 11:17, Kirill Shcherbatov wrote:
> 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
> ---
> http://github.com/tarantool/tarantool/tree/kshch/gh-4041-empty-tuple-update
> https://github.com/tarantool/tarantool/issues/4041
I've checked your patch into master, 2.1 and 1.10 branches.
--
Regards, Kirill Yukhin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-04-23 10:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-23 8:17 [tarantool-patches] [PATCH v1 1/1] box: fix empty tuple invalid update Kirill Shcherbatov
2019-04-23 10:11 ` [tarantool-patches] " Vladislav Shpilevoy
2019-04-23 10:17 ` Kirill Shcherbatov
2019-04-23 10:20 ` Vladislav Shpilevoy
2019-04-23 10:30 ` Kirill Yukhin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox