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 1tCiz6-00BZqn-7x for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Nov 2024 17:22:51 +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 1tCiz3-000hqU-HR for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Nov 2024 17:22:50 +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 1tCiz3-000hq5-8v for pgsql-bugs@lists.postgresql.org; Sun, 17 Nov 2024 17:22:49 +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 1tCiz0-002RVh-Ja for pgsql-bugs@lists.postgresql.org; Sun, 17 Nov 2024 17:22:49 +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 4AHHMiI23068213; Sun, 17 Nov 2024 12:22:44 -0500 From: Tom Lane To: Noah Misch cc: Alexander Lakhin , pgsql-bugs@lists.postgresql.org, Aleksander Alekseev , dhyan@nataraj.su Subject: Re: BUG #18708: regex problem: (?:[^\d\D]){0} asserts with "lp->nouts == 0 && rp->nins == 0" In-reply-to: <20241117161210.54.nmisch@google.com> References: <2242483.1731627374@sss.pgh.pa.us> <2344149.1731636867@sss.pgh.pa.us> <2631851.1731715737@sss.pgh.pa.us> <661fd81b-f069-8f30-1a41-e195c57449b4@gmail.com> <2745175.1731772978@sss.pgh.pa.us> <7dd96d86-bac0-4879-2555-276d2ef4a8db@gmail.com> <2958975.1731817729@sss.pgh.pa.us> <2988928.1731824798@sss.pgh.pa.us> <20241117161210.54.nmisch@google.com> Comments: In-reply-to Noah Misch message dated "Sun, 17 Nov 2024 08:12:10 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3068211.1731864164.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 17 Nov 2024 12:22:44 -0500 Message-ID: <3068212.1731864164@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Noah Misch writes: > On Sun, Nov 17, 2024 at 01:26:38AM -0500, Tom Lane wrote: >> arcarray =3D (struct arc **) MALLOC(totalinarcs * sizeof(struct arc *))= ; >> if (arcarray =3D=3D NULL) >> On a machine where malloc(0) returns NULL, this mistakenly >> thinks that's an error. > Either of those sound reasonable. The consequence of missing this hazar= d, a > deterministic ERROR, is modest. This affects just one platform, in the = oldest > branches. There's a lack of complaints. To me, all that would make the > one-line diff tempting. I dug through the MALLOC and REALLOC calls in backend/regex/ and convinced myself that this is the only one that's at risk. (Some of those conclusions depend on the assumption that a regex NFA never has nstates =3D=3D 0, but I think that's okay: we create start and end states to begin with and never remove them.) So the one-liner fix is looking attractive. I'd prefer a malloc wrapper for future-proofing if this code were likely to receive a lot of churn in the pre-v16 branches, but that seems pretty improbable at this point. >> So the right answer seems to be to figure out why we didn't >> back-patch that change. > I don't recall a specific reason or see one in the discussion of commit > bea3d7e38. It was done mainly to unblock commit db4f21e, which in turn > unblocked commit 0da096d. The last commit is heavy, so I can understand= it > skipping the back branches. If I were making a (weak) argument against > back-patching bea3d7e38, I might cite the extra memory use from > RegexpCacheMemoryContext and children. I think just on minimum-risk grounds, I wouldn't consider back-patching bea3d7e38. I had more in mind a bespoke three-line malloc wrapper function. But the one-line fix seems sufficient for the problem at hand. regards, tom lane