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 1wP6Ry-000R8t-2X for pgsql-hackers@arkaria.postgresql.org; Mon, 18 May 2026 22:28: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 1wP6Rw-003OWq-2b for pgsql-hackers@arkaria.postgresql.org; Mon, 18 May 2026 22:28:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wP6Rw-003OWi-1i for pgsql-hackers@lists.postgresql.org; Mon, 18 May 2026 22:28:37 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wP6Rv-00000000EkE-05fs for pgsql-hackers@lists.postgresql.org; Mon, 18 May 2026 22:28:36 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-3697c35eab7so1430315a91.0 for ; Mon, 18 May 2026 15:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779143315; x=1779748115; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=GU+HpAM2fAEdAmmkATBBZuuFiqNAoCAvWUkb02XVRAk=; b=KASS5b2GN6eK6GCJs9NjgVzWx0CHQzUI83WPUaMiMYy/KBs5N6P8U41ReVSZO8Bz/a vkbIHkgBQhQ8oaFdfRNMJTjcD2/dFa/7sPcfrbvljkS1J3V6b1fWeDmIlf7uRgQ+zXqv kTI/37FLejZBH7pzOLTwKvIJTmmVpjFbwomcfpNYVZsG8QLc0LVnach6zjMm0BYGkWmE Lh2r8GysMIeTDicOLjWPAgUUyVs5w4oF8w5Lb0SYCb6KHfdkxCPxOzCCidJV8hfYEqkl F+Vnln/J+GTEDWi3Ux8bbTj+gdXZIzk8FkiRvQeMBpQPGUtEOvozMxnwdXqqBWZ7HlwK HOVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779143315; x=1779748115; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=GU+HpAM2fAEdAmmkATBBZuuFiqNAoCAvWUkb02XVRAk=; b=hI/vVa+yyN6c6cr5RAplKDndNIylClIZLUERi89G9mm8eyJdC0J2lNKmhzrcGi/fK6 56+eybsDcCRulVohLpVgeF/Fu/X2Nud5bUbH1jdtws5rkOfmIwbEJnEFeLyI+MDN3TxE WxwIGQE8Pi+M12cQra5/bCdqzXTZlyHpXkevsAbNgl4kHc4nyD9hAB27+j35PmUNdP1R FC5TswCxa0/RUCA86UyIh/Os0hBcgBeN6whUgIwHsrBbFpZrFtJ0bAmVPsLW7qQ+YiDh RvuzoedBmw49jgdbBn2aEdaUrZttPlWTTSP1zAE0vrSTdLj164GMn3V84v5cOwhqi6Ov 1dnA== X-Forwarded-Encrypted: i=1; AFNElJ9Nu0DcpNSSYjC2d+Vqf3uzrM6gfD17HBb7q70XYFmiXPewyiA0IcNS5lVp66wUGQQWYl80J9AIb/BAZTCF@lists.postgresql.org X-Gm-Message-State: AOJu0YyTo7Yz7+LoGuBkrDdTZwI9XAMPUo7kJ9OomSu9sGHYXrXSLrmC DnshKk6yoMw+Y3YqRXlnIQXyl+KXBsHW4cvoSKHXVCZXhXN7XPkayXOv X-Gm-Gg: Acq92OGloAMZoLEyDzGA4sB4dvwPmjwpEEXw6htZNGhVyy5KxN+99AzY/uAXcu96dnf wGkJ5KUVf8RgNijNVdvSvla/rUzjUbDCLxEtnH2PGQsHDMhbuEKChu4IOVwEaTLUbBGSWuJ+wzk xj4qxPGwHKyH4BbCZg5WfdYRxA7JDlhf8Ki6a35abQTPjDL/mHzdNUkm0axLd29+Wp/9ewR0BOt dvJI/YI9fyrnGNmx63OZp7R5A+8XNyFL1Ye7VPJveT7ou+SFn+cgjJDYw5HdFRZRExJtszPAEe3 3I5TK8jZTfG7XwzTyuSXIxRAhlmUL2J4h0PnqvLlHsxK9xnc+ohalYFykMiFTS63NFHWva8HqKM WO2aLdDAMOdEN3/Uk9r+CU2NNGhoOXxg1iNXcmRKCbhYcuiPjQ/vReTmb9oq/UFMfsB8A4kVrCE srNSO/IEUlCFVJW/3UH3ifUTDqLuvBoPE= X-Received: by 2002:a17:90b:4b46:b0:369:b9db:b885 with SMTP id 98e67ed59e1d1-369b9dbc037mr6707150a91.15.1779143314819; Mon, 18 May 2026 15:28:34 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-369514aecaesm12457296a91.17.2026.05.18.15.28.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 May 2026 15:28:34 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: COPY FROM ON_ERROR SET_NULL bypasses domain NOT NULL with partial column list From: Chao Li In-Reply-To: Date: Tue, 19 May 2026 06:27:54 +0800 Cc: jian he , SATYANARAYANA NARLAPURAM , PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <0ED082D4-70CB-4144-8A00-EFE63FCC15B1@gmail.com> References: To: Fujii Masao X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On May 18, 2026, at 21:22, Fujii Masao wrote: >=20 > On Fri, Apr 17, 2026 at 12:59=E2=80=AFPM jian he = wrote: >>=20 >> On Fri, Apr 17, 2026 at 1:09=E2=80=AFAM SATYANARAYANA NARLAPURAM >> wrote: >>>=20 >>> HI hackers, >>>=20 >>> 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. >>>=20 >>> Fix by allocating with num_phys_attrs and indexing by attnum - 1, >>> consistent with all other per-column arrays in BeginCopyFrom(). >>>=20 >>> Patch is attached, and added a new test case to cover this scenario. >>>=20 >>=20 >> The patch looks good to me. >> I simplified the tests. >=20 > The patch looks good to me. Barring any objections, I will commit it. >=20 > Regards, >=20 > --=20 > Fujii Masao I also found this bug and reported it here [1]. I just reviewed v2, the = code change of the fix itself is exactly the same as my version in [1]. = The new test is slightly different from my version, but I think that = also works. [1] = https://www.postgresql.org/message-id/8A72720A-55AC-4D41-B9DF-5610307600E6= %40gmail.com Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/