Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kPZ0m-0006Hb-N8 for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Oct 2020 22:31:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kPZ0l-0001w5-LI for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Oct 2020 22:31:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kPZ0l-0001qF-FS for pgsql-bugs@lists.postgresql.org; Mon, 05 Oct 2020 22:31:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kPZ0g-0008Jw-VZ for pgsql-bugs@lists.postgresql.org; Mon, 05 Oct 2020 22:31:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 095MV8Si1819572; Mon, 5 Oct 2020 18:31:08 -0400 From: Tom Lane To: cam.daniel@gmail.com cc: pgsql-bugs@lists.postgresql.org, Stephen Frost Subject: Re: BUG #16655: pg_dump segfault when excluding postgis table In-reply-to: <16655-5c92d6b3a9438137@postgresql.org> References: <16655-5c92d6b3a9438137@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 05 Oct 2020 20:54:43 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1819570.1601937068.1@sss.pgh.pa.us> Date: Mon, 05 Oct 2020 18:31:08 -0400 Message-ID: <1819571.1601937068@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > I'm getting a segfault when trying to pg_dump a database containing the > postgis extension, but only when excluding the spatial_ref_sys table. Yeah, I can reproduce this here. You don't really need postgis. What I did was 1. Install the src/test/modules/test_pg_dump module into an empty database. 2. alter table regress_table_dumpable add check(col1 > 0); 3. pg_dump -T regress_table_dumpable d1 While I haven't traced through it in complete detail, what seems to be happening is A. checkExtensionMembership sees that the table belongs to an extension, hence marks it dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL | DUMP_COMPONENT_SECLABEL | DUMP_COMPONENT_POLICY); (This ends up setting only the SECLABEL and POLICY bits, I didn't check why.) B. processExtensionTables sees that the table is excluded by an exclusion switch, so it sets configtbl->interesting = false. (I've not verified whether B happens before or after A. But we definitely end up with a TableInfo having dobj.dump = 40, interesting = false.) C. getTableAttrs sees that the table is marked interesting = false, so it doesn't bother loading any subsidiary data; particularly not the checkexprs[] array. But ncheck is positive because getTables filled it. D. Since dobj.dump is non-zero, we eventually wind up at dumpTableSchema, which crashes because checkexprs is NULL. It's a bit surprising that it doesn't crash sooner, but whatever. We should absolutely not be in that code at all for a table we didn't load all the subsidiary data for. So I think the basic problem here is that checkExtensionMembership and processExtensionTables are not on the same page. We can't have interesting = false for a table that any of the dobj.dump bits are set for. Arguably, we should get rid of the "interesting" flag entirely now that we have dobj.dump. I can't see that it's anything but a foot-gun. Stephen, I think you touched this code last; any thoughts? regards, tom lane