From: Noah Misch <noah@leadboat.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix stale attribute pointer in COPY FROM error context.
Date: Mon, 09 Nov 2026 14:22:01 +0000
Message-ID: <E1xQQG1-000000003k2-4AWH@gemulon.postgresql.org> (raw)
Fix stale attribute pointer in COPY FROM error context.
Previously, cur_attname and cur_attval were left set when ON_ERROR was
'ignore' or 'set_null'. As a result, if an error was raised while
processing the next row, the COPY error context callback could
dereference a pointer that no longer belonged to it. cur_attval isn't
a copy of the field value; it points into attribute_buf, which the
next row resets and, for a longer line, repallocs. The callback
measures the value with strlen() before applying the display limit, so
the limit bounds what we print but not what we read. So depending on
what has reused the allocation, the CONTEXT line reports a value from
the previous row or bytes belonging to something else entirely.
file_fdw reaches the same code through its soft-error retry loop, so
on v18 and later, a SELECT or ANALYZE on such a foreign table hits
this too.
Fix this by making sure to clear both fields before processing the
next column data.
This also corrects the context reported for a REJECT_LIMIT overrun,
which is a statement-level error but was picking up the column and
value left behind by the last skipped row.
Backpatch to v17, where ON_ERROR was introduced.
Reported-by: 안지용 <jfdg1y76@gmail.com>
Backpatch-through: 17
Security: CVE-2026-116310
Branch
------
REL_17_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/3094cdb7d97384eb18587908f10583462a997a44
Author: Masahiko Sawada <msawada@postgresql.org>
Modified Files
--------------
src/backend/commands/copyfromparse.c | 4 ++++
src/test/regress/expected/copy2.out | 8 ++++++++
src/test/regress/sql/copy2.sql | 12 ++++++++++++
3 files changed, 24 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: Fix stale attribute pointer in COPY FROM error context.
In-Reply-To: <E1xQQG1-000000003k2-4AWH@gemulon.postgresql.org>
References: <E1xQQG1-000000003k2-4AWH@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