Skip to content

Commit 787e20b

Browse files
committed
Fix core dump in pg_dump --binary-upgrade on zero-column composite type.
This reverts nearly all of commit 28f6cab in favor of just using the typrelid we already have in pg_dump's TypeInfo struct for the composite type. As coded, it'd crash if the composite type had no attributes, since then the query would return no rows. Back-patch to all supported versions. It seems to not really be a problem in 9.0 because that version rejects the syntax "create type t as ()", but we might as well keep the logic similar in all affected branches. Report and fix by Rushabh Lathia.
1 parent 7c67b93 commit 787e20b

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8326,7 +8326,6 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
83268326
int i_attalign;
83278327
int i_attisdropped;
83288328
int i_attcollation;
8329-
int i_typrelid;
83308329
int i;
83318330
int actual_atts;
83328331

@@ -8347,8 +8346,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
83478346
"pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
83488347
"a.attlen, a.attalign, a.attisdropped, "
83498348
"CASE WHEN a.attcollation <> at.typcollation "
8350-
"THEN a.attcollation ELSE 0 END AS attcollation, "
8351-
"ct.typrelid "
8349+
"THEN a.attcollation ELSE 0 END AS attcollation "
83528350
"FROM pg_catalog.pg_type ct "
83538351
"JOIN pg_catalog.pg_attribute a ON a.attrelid = ct.typrelid "
83548352
"LEFT JOIN pg_catalog.pg_type at ON at.oid = a.atttypid "
@@ -8366,8 +8364,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
83668364
appendPQExpBuffer(query, "SELECT a.attname, "
83678365
"pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
83688366
"a.attlen, a.attalign, a.attisdropped, "
8369-
"0 AS attcollation, "
8370-
"ct.typrelid "
8367+
"0 AS attcollation "
83718368
"FROM pg_catalog.pg_type ct, pg_catalog.pg_attribute a "
83728369
"WHERE ct.oid = '%u'::pg_catalog.oid "
83738370
"AND a.attrelid = ct.typrelid "
@@ -8385,15 +8382,12 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
83858382
i_attalign = PQfnumber(res, "attalign");
83868383
i_attisdropped = PQfnumber(res, "attisdropped");
83878384
i_attcollation = PQfnumber(res, "attcollation");
8388-
i_typrelid = PQfnumber(res, "typrelid");
83898385

83908386
if (binary_upgrade)
83918387
{
8392-
Oid typrelid = atooid(PQgetvalue(res, 0, i_typrelid));
8393-
83948388
binary_upgrade_set_type_oids_by_type_oid(fout, q,
83958389
tyinfo->dobj.catId.oid);
8396-
binary_upgrade_set_pg_class_oids(fout, q, typrelid, false);
8390+
binary_upgrade_set_pg_class_oids(fout, q, tyinfo->typrelid, false);
83978391
}
83988392

83998393
qtypname = pg_strdup(fmtId(tyinfo->dobj.name));

0 commit comments

Comments
 (0)