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 1s01My-0006p9-K8 for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Apr 2024 15:50:44 +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 1s01Mv-000Bmq-4f for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Apr 2024 15:50:42 +0000 Received: from makus.postgresql.org ([72.32.157.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 1s01Mu-000Bmg-SV for pgsql-bugs@lists.postgresql.org; Thu, 25 Apr 2024 15:50:41 +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 1s01Mt-004bf4-Ar for pgsql-bugs@lists.postgresql.org; Thu, 25 Apr 2024 15:50:40 +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 43PFocJC3943233; Thu, 25 Apr 2024 11:50:38 -0400 From: Tom Lane To: David Rowley cc: Alexander Lakhin , Robert Haas , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17855: Uninitialised memory used when the name type value processed in binary mode of Memoize In-reply-to: References: <17855-5f523e0f9769a566@postgresql.org> Comments: In-reply-to David Rowley message dated "Wed, 24 Apr 2024 14:25:56 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3943231.1714060238.1@sss.pgh.pa.us> Date: Thu, 25 Apr 2024 11:50:38 -0400 Message-ID: <3943232.1714060238@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > I've attached another patch which uses another method to fix this, per > an idea from Andres Freund. I'd class it as a hack, but I don't have > any better ideas aside from the mammoth task of making name variable > length. Indexes on name typed columns simply don't store all 64 bytes > of the name, so it's not safe to have code that assumes a name Datum > points to 64 bytes. The patch makes it so such a Datum *will* point to > 64 bytes. I've tried to do this as cheaply as possible by saving the > indexes to name columns in a new array in IndexOnlyScanState. That > should make the overhead very small when indexes don't contain any > name-typed columns. I realize that this is just a draft patch, but the near-total lack of comments is still disappointing. Even at the draft stage, good comments are important to make it reviewable. I do not like testing "atttypid == NAMEOID" one bit. As noted, that will fail on domains over name. It will also result in unnecessary work when reading non-btree indexes that contain name, since I don't think anything else has the same hack that btree name_ops does (grep for cstring in pg_opclass.dat). I think the correct thing is to see whether the index opclass for the column is btree name_ops. We don't seem to have an oid_symbol macro for that, but it shouldn't be hard to add, at least in HEAD. regards, tom lane