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 1rMZ2k-005ERv-Nx for pgsql-bugs@arkaria.postgresql.org; Sun, 07 Jan 2024 19:42:47 +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 1rMZ2i-00HZC9-3B for pgsql-bugs@arkaria.postgresql.org; Sun, 07 Jan 2024 19:42:44 +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 1rMZ2h-00HZC1-RK for pgsql-bugs@lists.postgresql.org; Sun, 07 Jan 2024 19:42:43 +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 1rMZ2f-000MHI-9i for pgsql-bugs@lists.postgresql.org; Sun, 07 Jan 2024 19:42:42 +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 407Jgd3k1636927; Sun, 7 Jan 2024 14:42:39 -0500 From: Tom Lane To: exclusion@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18273: Incorrect memory access occurs when gist__int index is building on data containing 2^31-1 In-reply-to: <18273-9a832d1da122600c@postgresql.org> References: <18273-9a832d1da122600c@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sat, 06 Jan 2024 19:00:00 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1636925.1704656559.1@sss.pgh.pa.us> Date: Sun, 07 Jan 2024 14:42:39 -0500 Message-ID: <1636926.1704656559@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > As far as I can see, the loop for j shown below: > Datum > g_int_decompress(PG_FUNCTION_ARGS) > { > ... > for (i = 0; i < lenin; i += 2) > for (j = din[i]; j <= din[i + 1]; j++) > if ((!i) || *(dr - 1) != j) > *dr++ = j; > overflows when dln[i] == dln[i+1] == 2147483647. Yeah, you are right. Probably the simplest fix is to widen j to int64. I see that somebody has already int64-ified g_int_compress and internal_size (else we'd not get this far), but they missed this. Will fix, thanks for report! regards, tom lane