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.98.2) (envelope-from ) id 1xJ437-000000042tx-3fRL for pgsql-bugs@arkaria.postgresql.org; Tue, 20 Oct 2026 07:14:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xJ426-0000000B2Re-1esL for pgsql-bugs@arkaria.postgresql.org; Tue, 20 Oct 2026 07:13:14 +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.98.2) (envelope-from ) id 1xJ425-0000000B2RW-28NM for pgsql-bugs@lists.postgresql.org; Tue, 20 Oct 2026 07:13:14 +0000 Received: from fhigh-b1-smtp.messagingengine.com ([202.12.124.152]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xJ421-000000036sy-3mZc for pgsql-bugs@lists.postgresql.org; Tue, 20 Oct 2026 07:13:12 +0000 Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id C5FBE7A01BD for ; Tue, 20 Oct 2026 03:13:05 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Tue, 20 Oct 2026 03:13:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1792480385; x=1792566785; bh=3QBDnjsxin 86Qkjor879SHy/dRhg3xOAB437zmUX2u8=; b=gYDCeX0+pPMKqZrIMn++tlf1ES FJsAvdnPz68bgMNO0CgLNt3kkY6uoDUDqydv+SL/VsmFiCzWqSvxPBwkqGa/BuPO V0iXJYII56dGF9pVnJqF9GrhhGuo/9x3vP5Rq/W2ZxM2xaReFoT+FTyDynq7bgje XEBQ4cs5L93myezqnGUVuMqV8jLIZwLEGG5qJv7YLAMSVstUqxL04lZpkLYcovib Rr4lM2IEM2BGO6nCxmOaBJSDTB91sYcM0jLW9NwalUoJU/Sh+W6LCe7B0jwX6VND RM3h1mmbq+9Ii7+B17rhV8yvFv4vx8s6ddFaimarARhuT75y6fZPW8r0Lhag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1792480385; x=1792566785; bh=3QBDnjsxin86Qkjor879SHy/dRhg3xOAB43 7zmUX2u8=; b=sltbewcH7Dazm4yJifyeZ7sR8b07TZzf9zi9L3/gyj5MwnrxlIX CUuP6oSINmoi8+mRqtLELhOEZ6cBuL71XMSos4s2WdgOLq/GPyjHYsfUEEwUFCh0 1xTsGKxmPC+36gXlIu0iF25O6xgNMoS04fXCxejI+noIU6svcC8IWoslOnt7fLyt 1bxDg6O3MHdfhT2FfesyyxcuqcWdefQhb5jvndjsWpqNZfToqPdsQ83pXrmUNQp2 mx5C5qe3bhNOpRfksAaZEv2uXnUZgIS8ZmXl7qWVVjO68mC4Dr9/7tsEEgpaQKUv mwlaYVnRwlcOSn1G/LpUSGdt0Vj7VcY5J5g== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-06; repo=github.com/dkim2wg/interop; date=2026-10-08; sw=lmtpprox; action=sign d=paquier.xyz a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1792480385; d=paquier.xyz; mf=PG1pY2hhZWxAcGFxdWllci54eXo+; rt=PHBnc3FsLWJ1Z3NAbGlzdHMucG9zdGdyZXNxbC5vcmc+; s=fm2:rsa-sha256:JFNjCM5H79CJgbU8ZbvKldbbqj49acx1yy7W3gkwp2Ij+AE LcbK+lWlk79IrY/T49nVnLYctmHt8K9z2KjqRR+LC4+UMgtDizdMLVdXy7Y2+LON Pr5NCh1zURqDQl8US3dVqr21ileQMrHJ4KxTv2butqL1ppywnyxxOKx/eXEDqdJg f1Fys+OO58icldZbOiSpEKKrv6taDaMcmKlkQ2VmKJl67cMhgZtR9yWo7MKjxLrC NkGnwarbv+2KagibfbAnlDpD8rOZrN2X1Ne+oH1qpBJK2fdU4AdEnSfQzlLzbcms Td0/kPfjaLVSRllUTzzGuaSuzDh2Gu+Tm3UB+hg==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-06; repo=github.com/dkim2wg/interop; date=2026-10-08; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-disposition,content-type,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:tJ2xVIjcmvt1O5Ficx7GDcZCGvAi58Mp1kOf4O0myb8=:TWMJrEevLda5SgsQIL6O2k/EoEciH7CSJ8O0/47SiQE=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGsxZAg+c7fWX724V4O3nOlrFNTyFtSI6bb1Kh8Ga6ELOJkRkjxq8lYhBqjgM7YW4 ugK/+a+Q2IKH0XWzgnlwa9n/AU4ZKIN7RddSraOR5/413pYpdmA7SqwBHurlVD9B0xR8AX JlZNHBMXSs/CyHJ4wHyOmSLZvpSx+k2YrcJ0Edfq/YgBOxjEzSzgnYtO2CGWTG2MR22lCy 3uYCt2763ZlUMk5R8RvNQ8p7mCv4Hd8q33w+PADsT8cNlPD+xHGeXNEitK4aZgNtY7U3gp tsCQxSPE+KAeochzzs2jDxPCMe9a7PX0VmOfuuMmISFr6XXLSGUJSfMIR4bGSffuXILmhp tluqRkp4jZ3U4mkQWnLWyEXa3F1mlLTvalEO7Bq7e6l9Q9ks7YVE5Cg/ZJGcGCnudVl/bI FPtTigYQNIzURwPwwcjjRSBFKT/eXK6etlvwnkPD+vrryhiwdcGsQR69SjmXNITWM/8X3K XkieSLEZ2S34W1sXbyAXaWuZVGP7tLG+m0HOLihH9/b8Se1kz2h8Ar1J4lSUFszCJnVxPa iZ5rFLDA5cfenFMIvfYewBTBtLOhxu1AGkKx95GY8kF6OfC1Q7UTU6p7xjQYmAnSjkm0rF GH9PepD3yob8stTp0qrgHOEjNhPft6xsBaU+k0N3FOmKUSpRS8OwMpnLPXMA X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 20 Oct 2026 03:13:02 -0400 (EDT) Date: Tue, 20 Oct 2026 16:12:59 +0900 From: Michael Paquier To: shihao zhong Cc: Tomas Vondra , 1217816127@qq.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form Subject: Re: BUG #19763: ManualBug2 NULL pointer dereference in make_build_data via examine_expression bypass of lookup_var_a Message-ID: References: <19763-14da3f96c02f07e8@postgresql.org> <4a008244-3d3f-4563-8caf-0976fc59816f@vondra.me> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Q+wo1MLTFeZ65Qua" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Q+wo1MLTFeZ65Qua Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Oct 18, 2026 at 10:43:03PM -0400, shihao zhong wrote: > Here is a patch. It does for examine_expression() what 3b7a6fa1572 > did for examine_attribute(). >=20 > The test adds your typanalyze function to test_custom_types. It runs > your repro and also a single expression object, which builds only > expression statistics. Thanks for the patch. A couple of comments as I have played with this area in the recent past. I didn't think that this would be reachable in practice, but well, that's a fancy typanalyze callback that you have here. + /* + * The typanalyze function sees a different attstattarget here tha= n in + * lookup_var_attr_stats(), so it may reject the expression now. + */ + if (result->stats[idx] =3D=3D NULL) + { + pfree(result); + return NULL; + } I don't understand why this comment is adapted here; it just makes the situation more confusing to me. This just points to the fact that examine_expression() could return NULL depending on what the typanalyze callback decides to return. What your patch does it fancy enough in the callback by not having the function to be called twice. Nothing like that would happen in practice, still I agree that the backend should have more protections. I think that we should just ditch this comment. It's plain enough that examine_expression() can return NULL. /* evaluate expressions (if the statistics object has any) */ data =3D make_build_data(onerel, stat, numrows, rows, stats, statt= arget); + if (!data) + { + if (!IsAutoVacuumWorkerProcess()) + ereport(WARNING, + (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), + errmsg("statistics object \"%s.%s\" could not be = computed for relation \"%s.%s\"", + stat->schema, stat->name, + get_namespace_name(onerel->rd_rel->relname= space), + RelationGetRelationName(onerel)), + errtable(onerel))); + continue; + } This warning is a duplicate, FWIW. Not optimal, just feels slightly annoying. The patch is OK with this duplication, I guess.. If we begin to care about examine_expression(), I think that we ought to also care about build_expr_data(), its second caller, no? It looks like this could also be reached with a fancy undeterministic typanalyze callback. I have not tested this hypothesis, but it would be nice to make all the callers examine_expression() consistent. +-- Same with a single expression, building only expression statistics. +CREATE STATISTICS test_stats ON (func_int_custom(data)) FROM test_table; +ANALYZE test_table; +WARNING: statistics object "public.test_stats" could not be computed for = relation "public.test_table" This test is a duplicate of the first one. Let's remove it; it brings nothing new. -- Michael --Q+wo1MLTFeZ65Qua Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmrXFHsACgkQnvQgOdby QH0Gxw/6AvClQN+XIyMy4P7dNN+N3ryWIBlE8tLDOAqUB8tz2JzV1vNInrYwAJ72 cpVZkQJdP16vXTquAfQLONtq4ovebpy4rg1LUst+kPGFINMbS5Awhyh/tsobIp4Q lkRzLNjHUsFrWJM0dHJJTkTs/lKb5XQZBXbpzLh9lzNtaNaKKBQftkIrx6kM2CJf WJjmRJMiemcV7QbnJGiAT2GQjjFltBetxSNAYtvhS6vsT38Q+6t1isHDmXovRlCS PwyFz5JSXjxwhkcZNRO4AqFhmingix8ag/rqGX/Qxk3Gci8szKe0vOIyad/Z6tGF adMJ8WiamQKCGXngx/+0C+efjwdTT1xTqKBESvcRDwUP4KZaCQ/wkLHTlFa86JNi Ju0RgMA+Mmo7geoGpaFiAtfFgqS7TT8oxTIJJEeak8UDQJ1qU1IUitmTEgOfkYXw e8MWABx9pCr8rmFVK2mXy9wQN5EkK1FxGDJa5xlPJZ+vlt+b44nMVhPTkTXw2s3D eQwb8/+K7qvfx2ZNcM/dTm6SImPUh8u5vrxYg7fbDv1LI7DwaA7hE3B5satZe/Ds eTPJ9V4fIcY/sH1lGcHBxdPRhZB5acP2Rp9w4FPqBzishWf+lhuNlXMrPSF1lB6b B4219GAjBGipeYk3dDOgCAiTjdfaGWGCf4Pa/oKV01r4VinbSXo= =KDFJ -----END PGP SIGNATURE----- --Q+wo1MLTFeZ65Qua--