From: George Tarasov <george.v.tarasov@gmail.com>
To: pgsql-hackers@postgresql.org
Subject: [BUG?] missing array index may result in a wrong constraint name (pg_dump, bin-upgrade, >=18)
Date: Sat, 7 Mar 2026 03:28:14 +0300
Message-ID: <f3029f25-acc9-4cb9-a74f-fe93bcfb3a27@gmail.com> (raw)
Greetings!
I performed static code analysis and got an error: ALWAYS FALSE SUBEXPR!
Let's look at a little snippet (pg_dump.c:10203).
/*
* In binary upgrade of inheritance child tables, must have a
* constraint name that we can UPDATE later; same if there's a
* comment on the constraint.
*/
if ((dopt->binary_upgrade &&
!tbinfo->ispartition &&
!tbinfo->notnull_islocal) ||
^^^^^^^^^^^^^^^^^^^^^^^^ ALWAYS FALSE SUBEXPR!
!PQgetisnull(res, r, i_notnull_comment))
{
It seems like index "[j]" is missing for this subexpression to make any
sense.
"notnull_islocal" is an array of bools. It is _always_ created before
this snippet
in function "getTableAttrs()". So, the value of tbinfo->notnull_islocal
is _always_ TRUE
(it is a valid memory pointer), and therefore the entire subexpression
is _always_ FALSE.
And so, in binary upgrade mode this condition may not be evaluated as
expected
(when there's NO comment on the constraint!).
To be honest, I don't fully understand the overall logic behind these
preparations
for further processing (in pg_dump), but it seems like "[j]" index is
definitely missing.
That is how it should be.
/*
* In binary upgrade of inheritance child tables, must have a
* constraint name that we can UPDATE later; same if there's a
* comment on the constraint.
*/
if ((dopt->binary_upgrade &&
!tbinfo->ispartition &&
!tbinfo->notnull_islocal[j]) ||
^^^ MISSING ARRAY INDEX!
!PQgetisnull(res, r, i_notnull_comment))
{
Dear, Hackers! Please review.
Is there a really mistake here or am I wrong to raise this issue?
Thanks!
George Tarasov
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 using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: george.v.tarasov@gmail.com
Subject: Re: [BUG?] missing array index may result in a wrong constraint name (pg_dump, bin-upgrade, >=18)
In-Reply-To: <f3029f25-acc9-4cb9-a74f-fe93bcfb3a27@gmail.com>
* 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