From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 88949469719 for ; Thu, 20 Feb 2020 22:58:22 +0300 (MSK) Date: Thu, 20 Feb 2020 22:58:21 +0300 From: Nikita Pettik Message-ID: <20200220195821.GE95807@tarantool.org> References: <4f7cb05d8161597c0e58520b75af04167ce0b5e6.1581580784.git.imeevma@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <4f7cb05d8161597c0e58520b75af04167ce0b5e6.1581580784.git.imeevma@gmail.com> Subject: Re: [Tarantool-patches] [PATCH v2 1/1] sql: limit blob size during CAST AS INTEGER List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org On 13 Feb 11:16, imeevma@tarantool.org wrote: > >> +test:do_execsql_test( > >> + "cast-6.1", > >> + [[ > >> + CREATE TABLE t (a VARBINARY PRIMARY KEY); > >> + INSERT INTO t VALUES (X'33'), (X'372020202020'); > >> + SELECT a, CAST(a AS NUMBER), CAST(a AS INTEGER), CAST(a AS UNSIGNED) FROM t; > >> + DROP TABLE t; > >> + ]], { > >> + -- > >> + '3', 3, 3, 3, '7 ', 7, 7, 7 > >> + -- > >> + }) > >> + > >> +test:do_execsql_test( > >> + "cast-6.2", > >> + [[ > >> + CREATE TABLE t (a VARBINARY PRIMARY KEY, i INT); > >> + INSERT INTO t VALUES (X'33', 1); > >> + SELECT a, CAST(a AS NUMBER), CAST(a AS INTEGER), CAST(a AS UNSIGNED) FROM t; > >> + DROP TABLE t; > > > > What's the (in functional sense) difference between 6.1 and 6.2? > > > True, in this test it isn't obvious what it should show. I fixed > the test. I made this test to show that the '\0' at the end of the > BLOB is important. One possible way to solve this problem was to > limit the length of the decoded BLOB (without copying and adding > '\0'), but this could lead to an incorrect result of this test. > I mean this: > > tarantool> CREATE TABLE t (a VARBINARY PRIMARY KEY, i INT) WITH ENGINE = 'vinyl'; > --- > - row_count: 1 > ... > > tarantool> INSERT INTO t VALUES (X'33', 0x33); > --- > - row_count: 1 > ... So now you insert 0x33 instead of 1 to integer field. But how does it affect test? I failed to understand. In both cases you fetch and operate on blob, meanwhile integer field doesn't seem to be involved. > > tarantool> SELECT a, CAST(a AS NUMBER), CAST(a AS INTEGER), CAST(a AS UNSIGNED) FROM t; > --- > - metadata: > - name: A > type: varbinary > - name: CAST(a AS NUMBER) > type: number > - name: CAST(a AS INTEGER) > type: integer > - name: CAST(a AS UNSIGNED) > type: unsigned > rows: > - ['3', 33, 33, 33] > ... > > +-- > +-- In some cases, the absence of '\0' could lead to an incorrect > +-- result. Make sure this does not happen now. > +-- > test:do_execsql_test( > "cast-6.2", > [[ > CREATE TABLE t (a VARBINARY PRIMARY KEY, i INT); > - INSERT INTO t VALUES (X'33', 1); > + INSERT INTO t VALUES (X'33', 0x33); > SELECT a, CAST(a AS NUMBER), CAST(a AS INTEGER), CAST(a AS UNSIGNED) FROM t; > DROP TABLE t; > ]], { >