From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 37E2F24886 for ; Mon, 9 Sep 2019 14:56:32 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AN-PfTkOsshH for ; Mon, 9 Sep 2019 14:56:32 -0400 (EDT) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id E58C3247AF for ; Mon, 9 Sep 2019 14:56:31 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH v2 2/4] msgpack: make msgpackffi use encode_max_depth option Date: Mon, 9 Sep 2019 21:00:08 +0200 Message-Id: <945d59a2cc72f44f66e51c29e14cff5b4acae8c0.1568055477.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: alexander.turenko@tarantool.org Msgpack Lua module is not a simple set of functions. It is a global serializer object used by plenty of other Lua and C modules. Msgpack as a serializer can be configured, and in theory its configuration updates should affect all other modules. For example, a user could change encode_max_depth: require('msgpack').cfg({encode_max_depth = }) And that would make tuple:update() accept tables with depth without a crop. But in fact msgpack configuration didn't affect some places, such as this one. And all the others who use msgpackffi. This patch fixes it, for encode_max_depth option. Other options are still ignored. Part of #4434 --- src/lua/msgpackffi.lua | 3 +-- test/app-tap/msgpackffi.test.lua | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua index f7ee44291..65c57aa6e 100644 --- a/src/lua/msgpackffi.lua +++ b/src/lua/msgpackffi.lua @@ -4,7 +4,6 @@ local ffi = require('ffi') local buffer = require('buffer') local builtin = ffi.C local msgpack = require('msgpack') -- .NULL, .array_mt, .map_mt, .cfg -local MAXNESTING = 16 local int8_ptr_t = ffi.typeof('int8_t *') local uint8_ptr_t = ffi.typeof('uint8_t *') local uint16_ptr_t = ffi.typeof('uint16_t *') @@ -219,7 +218,7 @@ local function encode_r(buf, obj, level) elseif type(obj) == "string" then encode_str(buf, obj) elseif type(obj) == "table" then - if level >= MAXNESTING then -- Limit nested tables + if level >= msgpack.cfg.encode_max_depth then encode_nil(buf) return end diff --git a/test/app-tap/msgpackffi.test.lua b/test/app-tap/msgpackffi.test.lua index f2a8f254b..e26247625 100755 --- a/test/app-tap/msgpackffi.test.lua +++ b/test/app-tap/msgpackffi.test.lua @@ -36,7 +36,7 @@ local function test_offsets(test, s) end local function test_other(test, s) - test:plan(19) + test:plan(21) local buf = string.char(0x93, 0x6e, 0xcb, 0x42, 0x2b, 0xed, 0x30, 0x47, 0x6f, 0xff, 0xff, 0xac, 0x77, 0x6b, 0x61, 0x71, 0x66, 0x7a, 0x73, 0x7a, 0x75, 0x71, 0x71, 0x78) @@ -68,6 +68,30 @@ local function test_other(test, s) test:is(#s.encode(-0x8001), 5, "len(encode(-0x8001))") test:is(#s.encode(-0x80000000), 5, "len(encode(-0x80000000))") test:is(#s.encode(-0x80000001), 9, "len(encode(-0x80000001))") + + -- + -- gh-4434: msgpackffi does not care about msgpack serializer + -- configuration, but it should. + -- + local function check_depth(depth_to_try) + local t = nil + for i = 1, depth_to_try do t = {t} end + t = s.decode_unchecked(s.encode(t)) + local level = 0 + while t ~= nil do level = level + 1 t = t[1] end + return level + end + local msgpack = require('msgpack') + local max_depth = msgpack.cfg.encode_max_depth + local result_depth = check_depth(max_depth + 5) + test:is(result_depth, max_depth, + "msgpackffi uses msgpack.cfg.encode_max_depth") + + msgpack.cfg({encode_max_depth = max_depth + 5}) + result_depth = check_depth(max_depth + 5) + test:is(result_depth, max_depth + 5, "and uses it dynamically") + + msgpack.cfg({encode_max_depth = max_depth}) end tap.test("msgpackffi", function(test) -- 2.20.1 (Apple Git-117)