Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOLn1-0007Jn-T8 for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Mar 2021 14:44:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lOLn0-0005h8-Fk for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Mar 2021 14:44:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOLkh-0001yv-0R for pgsql-hackers@lists.postgresql.org; Mon, 22 Mar 2021 14:41:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOLke-0000ZL-Px for pgsql-hackers@lists.postgresql.org; Mon, 22 Mar 2021 14:41:53 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 12MEfmNd558767; Mon, 22 Mar 2021 10:41:48 -0400 From: Tom Lane To: Dilip Kumar cc: Justin Pryzby , Robert Haas , Andres Freund , Tomas Vondra , Alexander Korotkov , David Steele , Ildus Kurbangaliev , Dmitry Dolgov <9erthalion6@gmail.com>, Andrey Borodin , PostgreSQL Hackers Subject: Re: [HACKERS] Custom compression methods (mac+lz4.h) In-reply-to: References: <301730.1616276227@sss.pgh.pa.us> <20210320231957.GX11765@telsasoft.com> <309337.1616287493@sss.pgh.pa.us> <311370.1616290403@sss.pgh.pa.us> <414943.1616358751@sss.pgh.pa.us> <20210321204148.GB4203@telsasoft.com> <456616.1616360715@sss.pgh.pa.us> <504396.1616368310@sss.pgh.pa.us> <20210321234324.GC4203@telsasoft.com> <507597.1616370729@sss.pgh.pa.us> Comments: In-reply-to Dilip Kumar message dated "Mon, 22 Mar 2021 13:20:47 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <558765.1616424108.1@sss.pgh.pa.us> Date: Mon, 22 Mar 2021 10:41:48 -0400 Message-ID: <558766.1616424108@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dilip Kumar writes: > On Mon, Mar 22, 2021 at 5:22 AM Tom Lane wrote: >> Also, after studying the documentation for LZ4_decompress_safe >> and LZ4_decompress_safe_partial, I realized that liblz4 is also >> counting on the *output* buffer size to not be a lie. So we >> cannot pass it a number larger than the chunk's true decompressed >> size. The attached patch resolves the issue I'm seeing. > Okay, the fix makes sense. In fact, IMHO, in general also this fix > looks like an optimization, I mean when slicelength >= > VARRAWSIZE_4B_C(value), then why do we need to allocate extra memory > even in the case of pglz. So shall we put this check directly in > toast_decompress_datum_slice instead of handling it at the lz4 level? Yeah, I thought about that too, but do we want to assume that VARRAWSIZE_4B_C is the correct way to get the decompressed size for all compression methods? (If so, I think it would be better style to have a less opaque macro name for the purpose.) regards, tom lane