From: Noah Misch <noah@leadboat.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid out-of-bounds accesses in FDW batch inserts.
Date: Mon, 09 Nov 2026 14:21:59 +0000
Message-ID: <E1xQQFz-000000003dl-0HR0@gemulon.postgresql.org> (raw)
Avoid out-of-bounds accesses in FDW batch inserts.
Foreign data wrappers are expected to return the number of
successfully inserted tuples via ExecForeignBatchInsert's numSlots
parameter. Both the executor and COPY FROM use that number as the
length of the slot array. If the FDW reports more rows than we
sent, the backend proceeds to read past the end of the array.
(postgres_fdw is acutely affected: if the remote table has an
INSERT rule, the reported count may be higher.) To fix, clamp the
reported count to the number of rows that were sent.
This is a stopgap. Clamping keeps statements that happen to
succeed today succeeding, at the cost of misreporting the number
of rows. A better solution will likely involve reworking the API,
but that is left as a future exercise.
Reported-by: Sumedh Pathak <sumedhpathak@microsoft.com>
Reported-by: Sven Klemm <sven@tigerdata.com>
Author: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Jacob Champion <champion.p@gmail.com>
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Reviewed-by: Etsuro Fujita <etsuro.fujita@gmail.com>
Security: CVE-2026-120149
Backpatch-through: 14
Branch
------
REL_18_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/1e0a55a0fb26e13a6f0b1da87dea06957780b9e4
Author: Nathan Bossart <nathan@postgresql.org>
Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out | 18 ++++++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql | 15 +++++++++++++++
src/backend/commands/copyfrom.c | 3 +++
src/backend/executor/nodeModifyTable.c | 9 +++++++++
4 files changed, 45 insertions(+)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: noah@leadboat.com
Subject: Re: pgsql: Avoid out-of-bounds accesses in FDW batch inserts.
In-Reply-To: <E1xQQFz-000000003dl-0HR0@gemulon.postgresql.org>
References: <E1xQQFz-000000003dl-0HR0@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox