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 1qt8Fn-00Axi7-2H for pgsql-bugs@arkaria.postgresql.org; Wed, 18 Oct 2023 15:14:35 +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 1qt8Fk-005JNn-QB for pgsql-bugs@arkaria.postgresql.org; Wed, 18 Oct 2023 15:14:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qt8Fk-005JNe-HE for pgsql-bugs@lists.postgresql.org; Wed, 18 Oct 2023 15:14:33 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qt8Fg-001Np4-U4 for pgsql-bugs@lists.postgresql.org; Wed, 18 Oct 2023 15:14:32 +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 39IFERA23116808; Wed, 18 Oct 2023 11:14:28 -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: <01fc0593-e31e-463d-902c-dd43174acee2@oopacity.net> References: <01fc0593-e31e-463d-902c-dd43174acee2@oopacity.net> Comments: In-reply-to Flavien GUEDEZ message dated "Wed, 18 Oct 2023 16:21:57 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3116806.1697642067.1@sss.pgh.pa.us> Date: Wed, 18 Oct 2023 11:14:27 -0400 Message-ID: <3116807.1697642067@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Flavien GUEDEZ writes: > After some investigations about very corrupted toast data in one > postgres instance, I found that the pglz_decompress function (in > common/pg_lzcompress.c) does not check correctly where it copies data > from using memcpy(), which could result in segfault. > In this function, there are other checks to ensure that we do not copy > after the destination end, but not if we copy data from "before the > beginning". Hmm, would it not be better to add this check to the existing "Check for corrupt data" a bit further up? Then you'd only need one instance of the test, and only need to do it once per tag (note the comment pointing out that dp - off stays the same), and overall it'd be less surprising IMO. regards, tom lane