Skip to content

Commit 31021e7

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 870a980 commit 31021e7

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7309,7 +7309,6 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
73097309
int ntups;
73107310
int i_attname;
73117311
int i_atttypdefn;
7312-
int i_typrelid;
73137312
int i;
73147313

73157314
/* Set proper schema search path so type references list correctly */
@@ -7319,8 +7318,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
73197318
/* We assume here that remoteVersion must be at least 70300 */
73207319

73217320
appendPQExpBuffer(query, "SELECT a.attname, "
7322-
"pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
7323-
"typrelid "
7321+
"pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn "
73247322
"FROM pg_catalog.pg_type t, pg_catalog.pg_attribute a "
73257323
"WHERE t.oid = '%u'::pg_catalog.oid "
73267324
"AND a.attrelid = t.typrelid "
@@ -7341,14 +7339,11 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
73417339

73427340
i_attname = PQfnumber(res, "attname");
73437341
i_atttypdefn = PQfnumber(res, "atttypdefn");
7344-
i_typrelid = PQfnumber(res, "typrelid");
73457342

73467343
if (binary_upgrade)
73477344
{
7348-
Oid typrelid = atooid(PQgetvalue(res, 0, i_typrelid));
7349-
73507345
binary_upgrade_set_type_oids_by_type_oid(q, tyinfo->dobj.catId.oid);
7351-
binary_upgrade_set_relfilenodes(q, typrelid, false);
7346+
binary_upgrade_set_relfilenodes(q, tyinfo->typrelid, false);
73527347
}
73537348

73547349
appendPQExpBuffer(q, "CREATE TYPE %s AS (",

0 commit comments

Comments
 (0)