From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 92CA66EC55; Tue, 27 Jul 2021 10:41:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 92CA66EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627371700; bh=r+thtRjGNnxNbHv58oDakSL9+GUP8f7BHvalGKwQJjA=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=cfjTkrx5gCUTFqc+Tw11JsYoqRWx4+2+9lg4fNXjyS7xJ4YQ2s+ZeYNfCB/iuCbVN vPjTECenfpT8GpkVC4OiTHypxF5OtDw+wPLHu53p08i25E2+BXkRV4MoxIKChYhuNw OEFE4tiJ58tjA2qm5vILRU0898o4lB7wC50V7GQE= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [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 14FFC6EC55 for ; Tue, 27 Jul 2021 10:41:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 14FFC6EC55 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1m8Hic-00019b-69; Tue, 27 Jul 2021 10:41:38 +0300 To: tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 27 Jul 2021 10:41:37 +0300 Message-Id: <287af90465215d8f5dc37f1c147074387175bdf2.1627371599.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C3104FC76DFAAAAF7DA068FE323FAC4379182A05F5380850407066B22B7F6F1DBCC0C83D8454BBB250068391F71345B2BFCC79FD906EA6C307 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE709CF9AF650BAB6C1EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374B2D40F594293EAD8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C3D73D5D732ABC8717F9CC402606A0BB117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7BEA09003D200E0897EA5EB3AF187E4FF10BEE3B6203B67E9C2B6934AE262D3EE7EAB7254005DCEDF1D44946AC0875EC1E0A4E2319210D9B64D260DF9561598F01A9E91200F654B09D02A5090F3BCDFA8E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D75CEA0D7A80616E363516869D2CB7FA6195014DACEEE693CEB0FA9929BC6D98CE0B8BD686DA52171D7E09C32AA3244C35E00D559E6431CC6C02075C7BEB86065595C85A795C7BAE729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojMEANdStWW5/Ogj+W/lRbww== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D02DDA8411F79BE3353A7BF90DF7C15A483D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 1/1] sql: disallow cast of negative DOUBLE to UNSIGNED X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Prior to this patch it was possible to use CAST( AS UNSIGNED) and get negative result. For example, result of CAST(-1.5 AS UNSIGNED) was -1. This patch removes this possibility. Now such cast can only return UNSIGNED value. Closes #6010 --- https://github.com/tarantool/tarantool/issues/6010 https://github.com/tarantool/tarantool/tree/imeevma/gh-6010-disallow-double-to-int-cast ...-6010-disallow-negative-double-to-unsigned-cast | 4 ++++ src/box/sql/mem.c | 2 +- test/sql-tap/numcast.test.lua | 14 +++++++++++++- test/sql/types.result | 7 ++----- 4 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 changelogs/unreleased/gh-6010-disallow-negative-double-to-unsigned-cast diff --git a/changelogs/unreleased/gh-6010-disallow-negative-double-to-unsigned-cast b/changelogs/unreleased/gh-6010-disallow-negative-double-to-unsigned-cast new file mode 100644 index 000000000..566be594f --- /dev/null +++ b/changelogs/unreleased/gh-6010-disallow-negative-double-to-unsigned-cast @@ -0,0 +1,4 @@ +## bugfix/sql + +* Fixed explicit cast of negative DOUBLE to UNSIGNED, which could return +negative result (gh-6010). diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index fa80f6d5a..e4ce233e0 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1061,7 +1061,7 @@ mem_cast_explicit(struct Mem *mem, enum field_type type) case MEM_TYPE_BIN: return bytes_to_uint(mem); case MEM_TYPE_DOUBLE: - return double_to_int(mem); + return double_to_uint(mem); case MEM_TYPE_BOOL: return bool_to_int(mem); default: diff --git a/test/sql-tap/numcast.test.lua b/test/sql-tap/numcast.test.lua index b3aa64e76..20aea3c4b 100755 --- a/test/sql-tap/numcast.test.lua +++ b/test/sql-tap/numcast.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool local test = require("sqltester") -test:plan(31) +test:plan(32) --!./tcltestrunner.lua -- 2013 March 20 @@ -249,4 +249,16 @@ test:do_execsql_test( 0 , 0.33333333333333, 0.33333333333333 }) +-- +-- gh-6010: Make sure that a negative DOUBLE value cannot be explicitly cast to +-- UNSIGNED. +-- +test:do_catchsql_test( + "numcast-4", + [[ + SELECT CAST(-2.5 AS UNSIGNED); + ]], { + 1, "Type mismatch: can not convert double(-2.5) to unsigned" +}) + test:finish_test() diff --git a/test/sql/types.result b/test/sql/types.result index a0b8668be..c1e1a8ef1 100644 --- a/test/sql/types.result +++ b/test/sql/types.result @@ -1097,11 +1097,8 @@ box.execute("SELECT CAST(1.5 AS UNSIGNED);") ... box.execute("SELECT CAST(-1.5 AS UNSIGNED);") --- -- metadata: - - name: COLUMN_1 - type: unsigned - rows: - - [-1] +- null +- 'Type mismatch: can not convert double(-1.5) to unsigned' ... box.execute("SELECT CAST(true AS UNSIGNED);") --- -- 2.25.1