Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: tarantool-patches@freelists.org
Subject: [PATCH 2/2] tuple format: remove invalid assertion from tuple_format_iterator_next
Date: Wed, 22 May 2019 18:26:47 +0300	[thread overview]
Message-ID: <aad779db4511f48845cb82f4c73dcb9dfe3b854b.1558538748.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <e1d3fe8ab8eed65394ad17409401a93b6fcdc435.1558538748.git.vdavydov.dev@gmail.com>
In-Reply-To: <e1d3fe8ab8eed65394ad17409401a93b6fcdc435.1558538748.git.vdavydov.dev@gmail.com>

It's too early to assert msgpack type as an array when a multikey field
is encountered - we haven't checked the field type yet so the type might
as well be a map, in which case we will raise an error just a few lines
below. Remove the assertion and add a test case.
---
https://github.com/tarantool/tarantool/commits/dv/tuple-format-check-fixes

 src/box/tuple_format.c        |  1 -
 test/engine/multikey.result   | 28 ++++++++++++++++++++++++++++
 test/engine/multikey.test.lua | 12 ++++++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c
index 9b913306..02fadf1c 100644
--- a/src/box/tuple_format.c
+++ b/src/box/tuple_format.c
@@ -1138,7 +1138,6 @@ tuple_format_iterator_next(struct tuple_format_iterator *it,
 			 * and is equal to multikey index
 			 * comparison hint.
 			 */
-			assert(type == MP_ARRAY);
 			it->multikey_frame = mp_stack_top(&it->stack);
 		}
 		it->parent = &field->token;
diff --git a/test/engine/multikey.result b/test/engine/multikey.result
index e7326cb9..30208227 100644
--- a/test/engine/multikey.result
+++ b/test/engine/multikey.result
@@ -835,3 +835,31 @@ s.index.sk:select()
 s:drop()
 ---
 ...
+--
+-- Inserting a map where a multikey array is expected is
+-- handled gracefully: no crashes, just an error message.
+--
+s = box.schema.space.create('test', {engine = engine})
+---
+...
+_ = s:create_index('pk')
+---
+...
+_ = s:create_index('sk', {parts = {{'[2][*]', 'unsigned'}}})
+---
+...
+s:insert{1, {a = 1}} -- error
+---
+- error: 'Tuple field 2 type does not match one required by operation: expected array'
+...
+s:insert{2, {1}} -- ok
+---
+- [2, [1]]
+...
+s.index.sk:select()
+---
+- - [2, [1]]
+...
+s:drop()
+---
+...
diff --git a/test/engine/multikey.test.lua b/test/engine/multikey.test.lua
index 48eed2a3..6d974716 100644
--- a/test/engine/multikey.test.lua
+++ b/test/engine/multikey.test.lua
@@ -224,3 +224,15 @@ s:insert{7, {}} -- ok
 s:insert{8, {2}} -- ok
 s.index.sk:select()
 s:drop()
+
+--
+-- Inserting a map where a multikey array is expected is
+-- handled gracefully: no crashes, just an error message.
+--
+s = box.schema.space.create('test', {engine = engine})
+_ = s:create_index('pk')
+_ = s:create_index('sk', {parts = {{'[2][*]', 'unsigned'}}})
+s:insert{1, {a = 1}} -- error
+s:insert{2, {1}} -- ok
+s.index.sk:select()
+s:drop()
-- 
2.11.0

  reply	other threads:[~2019-05-22 15:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-22 15:26 [PATCH 1/2] tuple format: don't allow null where array/map is expected Vladimir Davydov
2019-05-22 15:26 ` Vladimir Davydov [this message]
2019-05-22 19:01   ` [tarantool-patches] Re: [PATCH 2/2] tuple format: remove invalid assertion from tuple_format_iterator_next Konstantin Osipov
2019-05-22 20:37   ` Vladimir Davydov
2019-05-22 19:00 ` [tarantool-patches] Re: [PATCH 1/2] tuple format: don't allow null where array/map is expected Konstantin Osipov
2019-05-22 20:37 ` Vladimir Davydov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aad779db4511f48845cb82f4c73dcb9dfe3b854b.1558538748.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH 2/2] tuple format: remove invalid assertion from tuple_format_iterator_next' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox