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.96) (envelope-from ) id 1wVLS9-001tcr-2s for pgsql-bugs@arkaria.postgresql.org; Fri, 05 Jun 2026 03:42:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wVLS8-009rVX-2S for pgsql-bugs@arkaria.postgresql.org; Fri, 05 Jun 2026 03:42:36 +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.96) (envelope-from ) id 1wVLS8-009rVP-1X for pgsql-bugs@lists.postgresql.org; Fri, 05 Jun 2026 03:42:36 +0000 Received: from mail-yx1-xb136.google.com ([2607:f8b0:4864:20::b136]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wVLS6-00000001Lvr-0imc for pgsql-bugs@lists.postgresql.org; Fri, 05 Jun 2026 03:42:35 +0000 Received: by mail-yx1-xb136.google.com with SMTP id 956f58d0204a3-6603d8697d2so1596705d50.0 for ; Thu, 04 Jun 2026 20:42:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780630952; cv=none; d=google.com; s=arc-20240605; b=CuJdr7+oOzWz+G9CvtoHRd6Thbuj6xotdHcvvIeKaSD8dc/6KYeZJ6NwOUS7h3mjVG 0xCHN0QbNmFcYpOtaeVp3v9ESimgch/2y8fvsPbDTYkwt4kWDryagZqX3FHvDYbR5zud kTS4chr9GUIgynfR/+r+rEmypSbWhx8elJpVy2jolTmEedVXiV4iVRQlwZkSiHD8oSGJ VEHE6oZPcJYNiZ+xiFf/l2DE/a4jraaSjg8CXjUYeR5m74JEk5PGX/Y9O44zUy9Ilz4A qTCDsznuGft0457rrQW5u49FlVNw4iDV7mY6dgUFT83HEsKGeiOt2ofKbqwxhNa6cvrW ezZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=PvCPFAETqLwicPfBFsJ6bLRcNI1di5VvfJa0rE4f3II=; fh=dDMBPQnMyaWMyxgCcptJ2bXlQph5MlUXj4sDYUYy6qE=; b=RWMGZEBZx2Ifi4zif2kdM7Ei4QLxnAxHT0VRtYO/zL26xJ4yaaB5DPu8cThKs5pG1p y3veUUU+rowolEEtcINribjYMoQ6pgxgHjL9NPgjzAfAc63zlG9YFazVrqwDfLM0Vrv9 VCtyfwQNWWmQV1mCl5E5uP/9YUhaAOqgT0NEhoJ3t4bQ0TNzybFPSnxKY9Sh91azuT9P cPVXJRzSN5WfshNQenphfT41++SPavmreq1aSWNdd8aN97Cz4aIBiDPNg4+qCpjy3mMd HbygGVO2A3R9WOQ5aH4eayg+48k4VOAzCfwR/8SUKc8v3GCQODpGqwnz+1A8kYnrdPWl skQA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780630952; x=1781235752; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=PvCPFAETqLwicPfBFsJ6bLRcNI1di5VvfJa0rE4f3II=; b=lzkvtmWrWDtCFr52HDKh+Y6UlgNS1vvRx2sXy2rULEGQ8frOEvemyrlWmIYurzs+Dt wg5RLl5ficZKAqUy6wkyOHgEJsEwy1dCdRPo5o1QZdlcDEHjgCEPhqDcu0WihTe4i1r7 2N5k8wxPkf+NoKnOpMrh4W8Y8sGhp0rgtEkuTkSAkWEAjwYDxBh2iG/M7l7U0ZgQIIec hDkJnmYgwBJwB7bYxdsfIqKjpVx3mpFVKsDYXleICp5Usio4jICkzwF61RSmAQ6BCJWF Ib6DJtx1iYQJPUnih7mbBwqfOerfqVVmXNwG4EJve5oP2RocRtc4W0cS13rFUvS3y1rJ LkiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780630952; x=1781235752; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=PvCPFAETqLwicPfBFsJ6bLRcNI1di5VvfJa0rE4f3II=; b=bVqtQuxqK8ob8BMHsGdSwS+63XFhL66SqKaGOtlSqdzUnaINhGDvWT6jYo5/zbGTBr l931tNvZ8MIVYLNatJ5jqNXRhPkpUdmrRbKNLk/FGITopAoa6+xXk68uPhGopiZEXVgL GPglezJ+u6hS3fug6cgncFwo0FGoHP51WOnJxYEFXxowmv3E94GloaqN6yTlTcwAMshc ldhHkMpRWr9BDf9VMXpO3oXbq0hKQohtjEJJ6L8ebFhJHLfryADFsbge3JfIdoH1I6XC hUIW4w0Ka5R0d6pZBbmdWcv2BOpwDOk8cX/AqstPlD/p3cQGvOMDLPdoqWC6K743g1yF Iiyg== X-Forwarded-Encrypted: i=1; AFNElJ+8zMNO9rcv8LZGnobwMojXj2oMXkS40cNvgIzwD6M9XVOI9XinPj/P7BoOp+EGcQ0EVj9QbZdDcNaE@lists.postgresql.org X-Gm-Message-State: AOJu0YwmHwwdKhXguPWlvKd2yZQ/5sLVdpNd5CHCHrwdTgO6PsOBy5Xk tUtAKVsUz2ZpA6+Q0zCJkuXouZdAV2IophuWmq3m9CShOPNdH0pdxg8NlbHkCRiu1Lx8HKo/6nl iHdWHuWQqWssyUdxHbn941dxrJ3thCJE= X-Gm-Gg: Acq92OG+58qSJrW95Eg6jHnDt5Th49mPIXdbit4RNzrlmx/HYJb4XbQ1uTzHdpDAt61 U/WaQ0DVn9WaPDbe9dYzrXmgnG/sfGDStEzj8o8vck/yermpUTwN7rbpnJ9QrLUvURGPDDEAccv G0sFF1sTcE+NGh9J8FtsZuw7m62ab50fGl9h+a/hJajXGR6UGrVr92oz5pCa6x2jMOwQDpVCBbf XrFSkIx8SvuQgQHmgO0UhamF+HESiTRGBc53WTg68CJ1n7P8BqSyGcTExIMXC8fBJTz4VJXzZnm ncWfegM7ebc6Ja2+fYh0H3qUYrqAt5MNeq8H2l84Qey0LT8Q X-Received: by 2002:a53:da86:0:b0:660:265f:b4dc with SMTP id 956f58d0204a3-66106f4bf59mr1200302d50.28.1780630951924; Thu, 04 Jun 2026 20:42:31 -0700 (PDT) MIME-Version: 1.0 References: <19508-e5f188183279219b@postgresql.org> In-Reply-To: From: Ayush Tiwari Date: Fri, 5 Jun 2026 09:12:20 +0530 X-Gm-Features: AVVi8Ce8LLTG5C6vwXVD7msRdy_BCWhD6xzUa365wHtgYsbkc5j7fmuB9uJ5TEY Message-ID: Subject: Re: BUG #19508: pg_buffercache_pages() crashes the backend with an incompatible caller-supplied record definition To: Fujii Masao Cc: n.kalinin@postgrespro.ru, pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000005d9930065379732c" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000005d9930065379732c Content-Type: text/plain; charset="UTF-8" Hi, On Fri, 5 Jun 2026 at 08:49, Fujii Masao wrote: > > Commit 257c8231bf9 changed pg_buffercache_pages() to materialize rows > directly > into a tuplestore. As a result, the function started using the > caller-supplied > RECORD descriptor as rsinfo->setDesc, so a mismatched column definition > list > could cause tuplestore_putvalues() to interpret returned Datums with > incorrect > types. > > Before that change, pg_buffercache_pages() exposed its actual tuple > descriptor > to the executor, allowing the executor's existing rowtype checks to reject > incompatible definitions with a normal error. > > The attached patch restores that behavior while keeping the > materialized-SRF > implementation. Thoughts? > Thanks for the patch, Fujii-san! I was looking into the bug last night, and the approach looks right to me. This still means InitMaterializedSRF() briefly creates the caller-derived descriptor before rsinfo->setDesc is replaced. That seems acceptable here: the descriptor lives only in the per-query context, and avoiding a local copy of InitMaterializedSRF() keeps the fix much smaller and less fragile. One small nit: build_buffercache_pages_tupledesc() names attribute 8 "usage_count", while the existing pg_buffercache view and the test use "usagecount". This probably does not affect the tupledesc_match() check, but I think it would be better to keep the existing spelling for consistency. Regards, Ayush --0000000000005d9930065379732c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

On Fri, 5 Jun 20= 26 at 08:49, Fujii Masao <masao= .fujii@gmail.com> wrote:

Commit 257c8231bf9 changed pg_buffercache_pages() to materialize rows direc= tly
into a tuplestore. As a result, the function started using the caller-suppl= ied
RECORD descriptor as rsinfo->setDesc, so a mismatched column definition = list
could cause tuplestore_putvalues() to interpret returned Datums with incorr= ect
types.

Before that change, pg_buffercache_pages() exposed its actual tuple descrip= tor
to the executor, allowing the executor's existing rowtype checks to rej= ect
incompatible definitions with a normal error.

The attached patch restores that behavior while keeping the materialized-SR= F
implementation. Thoughts?

Thanks for th= e patch, Fujii-san!

I was looking into the bug last night, and the a= pproach looks right to me.

This still means InitMa= terializedSRF() briefly creates the caller-derived
descriptor before rsi= nfo->setDesc is replaced. That seems acceptable here:
the descriptor = lives only in the per-query context, and avoiding a local
copy of InitMa= terializedSRF() keeps the fix much smaller and less fragile.

One sma= ll nit: build_buffercache_pages_tupledesc() names attribute 8
"usag= e_count", while the existing pg_buffercache view and the test use
&= quot;usagecount". This probably does not affect the tupledesc_match() = check,
but I think it would be better to keep the existing spelling for<= br>consistency.

Regards,
Ayush
--0000000000005d9930065379732c--