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.96) (envelope-from ) id 1whhJd-000Mzm-0A for pgsql-bugs@arkaria.postgresql.org; Thu, 09 Jul 2026 05:28:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1whhJb-00B2na-1x for pgsql-bugs@arkaria.postgresql.org; Thu, 09 Jul 2026 05:28:52 +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.96) (envelope-from ) id 1whhJb-00B2nR-1C for pgsql-bugs@lists.postgresql.org; Thu, 09 Jul 2026 05:28:52 +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.98.2) (envelope-from ) id 1whhJV-00000000Gfs-3wiU for pgsql-bugs@lists.postgresql.org; Thu, 09 Jul 2026 05:28:51 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 6695SREq2411430; Thu, 9 Jul 2026 01:28:27 -0400 From: Tom Lane To: Ewan Young cc: Heikki Linnakangas , Peter Eisentraut , 1217816127@qq.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19545: Integer truncation of `GinTuple.keylen` causes out-of-bounds read in parallel GIN index build In-reply-to: References: <19545-0f25b7e47351e8fc@postgresql.org> Comments: In-reply-to Ewan Young message dated "Thu, 09 Jul 2026 13:16:54 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2411428.1783574907.1@sss.pgh.pa.us> Date: Thu, 09 Jul 2026 01:28:27 -0400 Message-ID: <2411429.1783574907@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ewan Young writes: > Agreed, that's clearly better. v3 (attached) uses Size for > GinTuple.keylen (GinBuffer.keylen already was Size), and also for the > local in _gin_build_tuple(), which was the int that truncated > VARSIZE_ANY() in the first place. Am I reading this correctly that you propose using Size for the length of the key value (keylen) along with int for the length of the whole tuple (tuplen)? { int tuplen; /* length of the whole tuple */ OffsetNumber attrnum; /* attnum of index key */ - uint16 keylen; /* bytes in data for key value */ + Size keylen; /* bytes in data for key value */ int16 typlen; /* typlen for key */ bool typbyval; /* typbyval for key */ signed char category; /* category: normal or NULL? */ Please explain how that's sane. I kind of agree with the upthread comment that we should just reject key lengths exceeding BLCKSZ or so up-front, rather than fooling around with these field widths. This patch widens GinTuple noticeably, and will do so more if we also widen tuplen. Is that free? regards, tom lane