Fix COPY FROM ON_ERROR SET_NULL with selective column list
Fujii Masao <fujii@postgresql.org>
Fix COPY FROM ON_ERROR SET_NULL with selective column list When using COPY FROM ... ON_ERROR SET_NULL with a selective column list, the domain_with_constraint array was incorrectly allocated based on the length of the target column list. While the array was populated sequentially, CopyFromTextLikeOneRow attempted to access it using the physical attribute index (attnum - 1). This mismatch caused out-of-bounds reads when targeting high-numbered columns, allowing NULL values to bypass NOT NULL domain checks and be silently inserted. Fix by allocating the array to match the total number of physical attributes (num_phys_attrs) and indexing via attnum - 1, bringing it into alignment with other per-column arrays in BeginCopyFrom. Author: SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com> Reviewed-by: Jian He <jian.universality@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Fujii Masao <masao.fujii@gmail.com> Discussion: https://postgr.es/m/CAHg+QDdej0c0gWJi2FnbirzhgzyZNPiTwC1P5B_-dSNCzq-91A@mail.gmail.com
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/commands/copyfrom.c | modified | +2 −6 |
| src/test/regress/expected/copy2.out | modified | +4 −0 |
| src/test/regress/sql/copy2.sql | modified | +4 −0 |
Discussion
- COPY FROM ON_ERROR SET_NULL bypasses domain NOT NULL with partial column list 5 messages · 2026-04-16 → 2026-05-19