Re: COPY FROM ON_ERROR SET_NULL bypasses domain NOT NULL with partial column list

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: COPY FROM ON_ERROR SET_NULL bypasses domain NOT NULL with partial column list
Date: 2026-04-17 03:58:48
Message-ID: CACJufxEYGY5twGooBDU4ttpb0SOQuOb8dYKoBsEML8dObAf4ZQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Apr 17, 2026 at 1:09 AM SATYANARAYANA NARLAPURAM
<satyanarlapuram(at)gmail(dot)com> wrote:
>
> HI hackers,
>
> domain_with_constraint[] was allocated with list_length(attnumlist)
> elements and indexed sequentially via foreach_current_index(), but
> copyfromparse.c accesses it via attnum - 1 (physical attribute index).
> With a partial column list targeting high-numbered columns, this caused
> an out-of-bounds read that bypassed domain NOT NULL checks, silently
> inserting NULL into NOT NULL domain columns.
>
> Fix by allocating with num_phys_attrs and indexing by attnum - 1,
> consistent with all other per-column arrays in BeginCopyFrom().
>
> Patch is attached, and added a new test case to cover this scenario.
>

The patch looks good to me.
I simplified the tests.

--
jian
https://www.enterprisedb.com/

Attachment Content-Type Size
v2-0001-Fix-COPY-FROM-ON_ERROR-SET_NULL-with-selective-column-list.patch text/x-patch 4.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Lakshmi N 2026-04-17 04:20:52 Re: Reject invalid databases in pg_get_database_ddl()
Previous Message Xiaopeng Wang 2026-04-17 03:47:34 Re: [doc] pg_ctl: fix wrong description for -l