From: Tom Lane Date: Mon, 6 Apr 2026 18:22:17 +0000 (-0400) Subject: Avoid unsafe access to negative index in a TupleDesc. X-Git-Tag: REL_15_18~57 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=07e833e3cff3da136980c7a4e30e965f825ae83c;p=thirdparty%2Fpostgresql.git Avoid unsafe access to negative index in a TupleDesc. Commit aa606b931 installed a test that would reference a nonexistent TupleDesc array entry if a system column is used in COPY FROM WHERE. Typically this would be harmless, but with bad luck it could result in a phony "generated columns are not supported in COPY FROM WHERE conditions" error, and at least in principle it could cause SIGSEGV. (Compare 570e2fcc0 which fixed the identical problem in another place.) Also, since c98ad086a it throws an Assert instead. In the back branches, just guard the test to make it a safe no-op for system columns. Commit 21c69dc73 installed a more aggressive answer in master. Reported-by: Alexander Lakhin Author: Tom Lane Discussion: https://postgr.es/m/6f435023-8ab6-47c2-ba07-035d0c4212f9@gmail.com Backpatch-through: 14-18 --- diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index e7efb811f66..a334f6b42b1 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -169,7 +169,8 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt, * generated columns are not yet computed when the filtering * happens. */ - if (TupleDescAttr(RelationGetDescr(rel), attno - 1)->attgenerated) + if (attno > 0 && + TupleDescAttr(RelationGetDescr(rel), attno - 1)->attgenerated) ereport(ERROR, errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("generated columns are not supported in COPY FROM WHERE conditions"),