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 25CF46BD3C; Tue, 23 Mar 2021 12:35:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 25CF46BD3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616492110; bh=4E8y9VpZESOAJXHt4Bs3M54FbJgS/WZDqRm7BIH1F7k=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Ob2CXl3YvRoxwchFrW6z2m+00bQICRKpCYO6t+z+H4sRgM1YI/Egaw2VJN18stKPa HkRhiCCIujimn+5tkwomHdKXWCBlGEbDyJGNs7zM8g80byreJOfv/8RkjQ0/3su52a B0XmToe/OpMPInFWHflsP0RBuMzF/4hoo743RQlA= Received: from smtp37.i.mail.ru (smtp37.i.mail.ru [94.100.177.97]) (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 C7B3671828 for ; Tue, 23 Mar 2021 12:34:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C7B3671828 Received: by smtp37.i.mail.ru with esmtpa (envelope-from ) id 1lOdQv-0004YW-0N; Tue, 23 Mar 2021 12:34:41 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:34:40 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F179C48A9DDACBFB6F5347129BC2C9341C182A05F538085040AD336C4D09D767462AC5969D4F33B172D468D7FCDD8BA23CF18EDD367568E838 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE77806F8AEFB2C8BE8EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637D84D274D72FCF47F8638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C686AF563A045C75EFFAC6D6107280F3C5EA778A1507B81C8A471835C12D1D9774AD6D5ED66289B5259CC434672EE6371117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658359CC434672EE6371117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF434A9803D6DF6E63BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6A64B1FF5BBC4A9AC76E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B3BBE47FD9DD3FB59A8DF7F3B2552694A57739F23D657EF2B13377AFFFEAFD26923F8577A6DFFEA7C7D149460FF1CF91893EC92FD9297F6715571747095F342E857739F23D657EF2BD5E8D9A59859A8B6EC71F829093BE88A089D37D7C0E48F6C5571747095F342E857739F23D657EF2B6825BDBE14D8E7024847893F9AA87235E5BFE6E7EFDEDCD789D4C264860C145E X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75EFFAC6D6107280F3C5EA778A1507B81C89C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3455049D7B43D89D64E3779A604CF12DF7AEB25538B0CC8B51910064B5770EAEC1D4DBC11FC48AF3F61D7E09C32AA3244CF5BF503F823C566A5231E71D90BE1E6C69B6CAE0477E908DFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXh0z1dnC/bBjPLoXfwoyMXT X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED325C5CEA43FE659F2AC5969D4F33B172B9A8FEFFB5F7F2D55105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 01/53] sql: enchance vdbe_decode_msgpack_into_mem() 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" Currently, vdbe_decode_msgpack_into_mem() creates a MEM that is not properly initialized in case msgpack contains MP_EXT, MP_MAP, or MP_ARRAY fields. Also, it doesn't set field_type. Needed for #5818 --- src/box/sql/vdbe.c | 22 --------------- src/box/sql/vdbeaux.c | 64 ++++++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 3b3b1f01d..9a4f38bb9 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -846,16 +846,6 @@ vdbe_field_ref_fetch_data(struct vdbe_field_ref *field_ref, uint32_t fieldno) return field_begin; } -static inline enum field_type -vdbe_field_ref_fetch_type(struct vdbe_field_ref *field_ref, uint32_t fieldno) -{ - const struct tuple_field *tf = - vdbe_field_ref_fetch_field(field_ref, fieldno); - if (tf == NULL || tf->type == FIELD_TYPE_ANY) - return field_type_MAX; - return tf->type; -} - /** * Fetch field by fieldno using vdbe_field_ref and store result * in dest_mem. @@ -879,17 +869,6 @@ vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno, if (vdbe_decode_msgpack_into_mem(data, dest_mem, &dummy) != 0) return -1; - /* - * MsgPack map, array or extension (unsupported in sql). - * Wrap it in a blob verbatim. - */ - if (dest_mem->flags == 0) { - dest_mem->z = (char *) data; - dest_mem->n = vdbe_field_ref_fetch_data(field_ref, - fieldno + 1) - data; - dest_mem->flags = MEM_Blob | MEM_Ephem | MEM_Subtype; - dest_mem->subtype = SQL_SUBTYPE_MSGPACK; - } /* * Add 0 termination (at most for strings) * Not sure why do we check MEM_Ephem @@ -909,7 +888,6 @@ vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno, dest_mem->flags |= MEM_Term; } UPDATE_MAX_BLOBSIZE(dest_mem); - dest_mem->field_type = vdbe_field_ref_fetch_type(field_ref, fieldno); return 0; } diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c index 91b64316e..90c4b73c0 100644 --- a/src/box/sql/vdbeaux.c +++ b/src/box/sql/vdbeaux.c @@ -2793,38 +2793,62 @@ vdbe_decode_msgpack_into_mem(const char *buf, struct Mem *mem, uint32_t *len) { const char *start_buf = buf; switch (mp_typeof(*buf)) { - case MP_ARRAY: - case MP_MAP: - case MP_EXT: - default: { - mem->flags = 0; + case MP_ARRAY: { + mem->z = (char *)buf; + mp_next(&buf); + mem->n = buf - mem->z; + mem->flags = MEM_Blob | MEM_Ephem | MEM_Subtype; + mem->subtype = SQL_SUBTYPE_MSGPACK; + mem->field_type = FIELD_TYPE_ARRAY; + break; + } + case MP_MAP: { + mem->z = (char *)buf; + mp_next(&buf); + mem->n = buf - mem->z; + mem->flags = MEM_Blob | MEM_Ephem | MEM_Subtype; + mem->subtype = SQL_SUBTYPE_MSGPACK; + mem->field_type = FIELD_TYPE_MAP; + break; + } + case MP_EXT: { + mem->z = (char *)buf; + mp_next(&buf); + mem->n = buf - mem->z; + mem->flags = MEM_Blob | MEM_Ephem; + mem->field_type = FIELD_TYPE_VARBINARY; break; } case MP_NIL: { mp_decode_nil(&buf); mem->flags = MEM_Null; + mem->field_type = field_type_MAX; break; } case MP_BOOL: { mem->u.b = mp_decode_bool(&buf); mem->flags = MEM_Bool; + mem->field_type = FIELD_TYPE_BOOLEAN; break; } case MP_UINT: { uint64_t v = mp_decode_uint(&buf); mem->u.u = v; mem->flags = MEM_UInt; + mem->field_type = FIELD_TYPE_INTEGER; break; } case MP_INT: { mem->u.i = mp_decode_int(&buf); mem->flags = MEM_Int; + mem->field_type = FIELD_TYPE_INTEGER; break; } case MP_STR: { /* XXX u32->int */ mem->n = (int) mp_decode_strl(&buf); mem->flags = MEM_Str | MEM_Ephem; + mem->field_type = FIELD_TYPE_STRING; install_blob: mem->z = (char *)buf; buf += mem->n; @@ -2834,18 +2858,33 @@ install_blob: /* XXX u32->int */ mem->n = (int) mp_decode_binl(&buf); mem->flags = MEM_Blob | MEM_Ephem; + mem->field_type = FIELD_TYPE_VARBINARY; goto install_blob; } case MP_FLOAT: { mem->u.r = mp_decode_float(&buf); - mem->flags = sqlIsNaN(mem->u.r) ? MEM_Null : MEM_Real; + if (sqlIsNaN(mem->u.r)) { + mem->flags = MEM_Null; + mem->field_type = field_type_MAX; + } else { + mem->flags = MEM_Real; + mem->field_type = FIELD_TYPE_DOUBLE; + } break; } case MP_DOUBLE: { mem->u.r = mp_decode_double(&buf); - mem->flags = sqlIsNaN(mem->u.r) ? MEM_Null : MEM_Real; + if (sqlIsNaN(mem->u.r)) { + mem->flags = MEM_Null; + mem->field_type = field_type_MAX; + } else { + mem->flags = MEM_Real; + mem->field_type = FIELD_TYPE_DOUBLE; + } break; } + default: + unreachable(); } *len = (uint32_t)(buf - start_buf); return 0; @@ -2868,15 +2907,8 @@ sqlVdbeRecordUnpackMsgpack(struct key_def *key_def, /* Information about the rec pMem->z = 0; uint32_t sz = 0; vdbe_decode_msgpack_into_mem(zParse, pMem, &sz); - if (sz == 0) { - /* MsgPack array, map or ext. Treat as blob. */ - pMem->z = (char *)zParse; - mp_next(&zParse); - pMem->n = zParse - pMem->z; - pMem->flags = MEM_Blob | MEM_Ephem; - } else { - zParse += sz; - } + assert(sz != 0); + zParse += sz; pMem++; } } -- 2.25.1