Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pb2Fz-0003CP-5O for pgsql-bugs@arkaria.postgresql.org; Sat, 11 Mar 2023 16:39:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pb2Fw-0000Ui-8q for pgsql-bugs@arkaria.postgresql.org; Sat, 11 Mar 2023 16:39:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pb2Fw-0000UZ-0f for pgsql-bugs@lists.postgresql.org; Sat, 11 Mar 2023 16:39:40 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pb2Fp-0006if-6a for pgsql-bugs@lists.postgresql.org; Sat, 11 Mar 2023 16:39:39 +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 32BGdU5V1190343; Sat, 11 Mar 2023 11:39:30 -0500 From: Tom Lane To: exclusion@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17830: Incorrect memory access in trgm_regexp In-reply-to: <17830-57ff5f89bdb02b09@postgresql.org> References: <17830-57ff5f89bdb02b09@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sat, 11 Mar 2023 08:00:01 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1190341.1678552770.1@sss.pgh.pa.us> Date: Sat, 11 Mar 2023 11:39:30 -0500 Message-ID: <1190342.1678552770@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: > When the following script executed: > CREATE EXTENSION pg_trgm; > CREATE TABLE t(t text); > CREATE INDEX t_idx_gin ON t USING gin (t gin_trgm_ops); > SELECT * FROM t WHERE t ~ '.*$x'; > valgrind detects an invalid memory read: > ... > The invalid access occurs in the line: > while (j < arcsCount && arcs[j].sourceState == i) > here arcsCount == 1 even when arcs contains no elements, due to the > assignment above: > arcsCount = (p2 - arcs) + 1; Yeah, that de-duplication code is incorrectly assuming that the NFA has more than zero arcs, which it doesn't because the regex compiler saw that the pattern is unsatisfiable. Thanks for the report! regards, tom lane