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 1tChsq-00Az4p-PH for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Nov 2024 16:12:20 +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 1tChsn-000MWK-Q7 for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Nov 2024 16:12:18 +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 1tChsn-000MVz-8D for pgsql-bugs@lists.postgresql.org; Sun, 17 Nov 2024 16:12:18 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tChsj-002R3I-Im for pgsql-bugs@lists.postgresql.org; Sun, 17 Nov 2024 16:12:16 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2ea5a22d80cso272339a91.0 for ; Sun, 17 Nov 2024 08:12:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1731859932; x=1732464732; darn=lists.postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=4sB05S2ddie4udjwkcjSDlfMdT9rUwRFOMqFJ++gdn8=; b=O7qBuVLw5DF/UPh53D4ohmSzc2zJirRa7f+7imJb5GM7ed4NHKMGuqczsJRi5/GMPo hgNydDXjGviKMLo3yuDWmTBAoPNriIc4XlnWUWz4l+zybOg8VJ+P4RGjaGgl+Be1uOnB APgQsYR3/G+g+aDakVfSyUEdiEFvsie5c1dLg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731859932; x=1732464732; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4sB05S2ddie4udjwkcjSDlfMdT9rUwRFOMqFJ++gdn8=; b=HwELeQYwpwGN5d2Fp5+bqgDXhgwq812gL/gWL4sG+XokjQniyKSL2ZGmAypZ3SLHRa OYUHB4sLaKDoXKJQsVABs6FB1PK+JFN1BPnsxFl/VHB76EYwH9fiADu8Ysu8XFJpbbxp OqRsxDOD3W+61ua5TGCxMkpQxTNs0P7ohI/Vm5ToFsqPvzyT9Sn0ZiAMQahTOJxM2Wc1 hZbjrJkX+rbwwCupkR9pjNJQTFrTA1XGHxOo7GieuMEfkC084fMFx/FH/kYLzrBv63jR PYnEixH089aeVHXy3u5TNwsY24fmCM+4/rAERJV2xW4YPxz4No24rz+uD3yDDfO0cMd5 +BLg== X-Forwarded-Encrypted: i=1; AJvYcCV1dzWwWNw4DuQBgqE6TC8lZv011dDeppDGkuyccCEeafNTht/JedTJV+qhQON0FaCGZK4GgarvtPYJ@lists.postgresql.org X-Gm-Message-State: AOJu0YybdMUcsWiSRxq0qfiYxoACrWQBhi1hUmMnOyek4MCIMnM3GM03 U7e0XbsThRykb11J9qGC/Fum+UX2nLVCqFz70CGjZOk/JqQkbr7ZymxjuQLQNQ== X-Google-Smtp-Source: AGHT+IFOhS7LZv9+DpdqCdwbHQBZc6VqIpxu4QP+lnJeEe4eP3jsab6g7pzJ08RYmnMGy30W1NPCcg== X-Received: by 2002:a17:90b:1e4b:b0:2ea:5e0c:283d with SMTP id 98e67ed59e1d1-2ea5e1b73f4mr2438233a91.26.1731859932491; Sun, 17 Nov 2024 08:12:12 -0800 (PST) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0ec8034sm42291515ad.72.2024.11.17.08.12.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Nov 2024 08:12:12 -0800 (PST) Date: Sun, 17 Nov 2024 08:12:10 -0800 From: Noah Misch To: Tom Lane 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" Message-ID: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2988928.1731824798@sss.pgh.pa.us> User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Nov 17, 2024 at 01:26:38AM -0500, Tom Lane wrote: > arcarray = (struct arc **) MALLOC(totalinarcs * sizeof(struct arc *)); > if (arcarray == NULL) > { > NERR(REG_ESPACE); > ... > > On a machine where malloc(0) returns NULL, this mistakenly > thinks that's an error. > > I verified that > > - if (arcarray == NULL) > + if (arcarray == NULL && totalinarcs != 0) > > makes the failure go away, but I wonder if any other places in > backend/regex/ are at the same hazard. Maybe the smartest fix > would be to put in a wrapper layer that does what pg_malloc > does: > > /* Avoid unportable behavior of malloc(0) */ > if (size == 0) > size = 1; Either of those sound reasonable. The consequence of missing this hazard, 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. > One other point is that this theory fails to explain why > hornet didn't fail in the v16 branch ... oh, wait: > v15 has > > #define MALLOC(n) malloc(n) > > where later branches have > > #define MALLOC(n) palloc_extended((n), MCXT_ALLOC_NO_OOM) > > 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.