Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qtHCt-00BitE-L7 for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Oct 2023 00:48:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qtHCr-00Apnx-FL for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Oct 2023 00:48:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qtHCr-00Apnp-6l for pgsql-bugs@lists.postgresql.org; Thu, 19 Oct 2023 00:48:09 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qtHCn-001AoG-JC for pgsql-bugs@lists.postgresql.org; Thu, 19 Oct 2023 00:48:08 +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 39J0m3fq3235131; Wed, 18 Oct 2023 20:48:04 -0400 From: Tom Lane To: Flavien GUEDEZ cc: pgsql-bugs@lists.postgresql.org Subject: Re: Insufficient memory access checks in pglz_decompress In-reply-to: References: <01fc0593-e31e-463d-902c-dd43174acee2@oopacity.net> <3116807.1697642067@sss.pgh.pa.us> Comments: In-reply-to Flavien GUEDEZ message dated "Wed, 18 Oct 2023 18:46:56 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3235129.1697676483.1@sss.pgh.pa.us> Date: Wed, 18 Oct 2023 20:48:03 -0400 Message-ID: <3235130.1697676483@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Flavien GUEDEZ writes: > Thanks for your feedback, you are definitely right, I did not notice > that (dp - off) was staying the same in the while loop. > Here is another much smaller patch. I thought of another thing we should change: it's better to perform the test as "off > (dp - dest)" than the way you formulated it. "dp - dest" is certainly computable, since it's the number of bytes we've written to the output buffer so far. But "dp - off" could, with bad luck and a buffer near the start of memory, wrap around to look like it's after "dest". Pushed with that change and a little fiddling with the comment. Thanks for the report! regards, tom lane