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 1nKtVW-0004PD-8k for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Feb 2022 03:00:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nKtVU-0008DG-2P for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Feb 2022 03:00:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nKtVT-0008D7-La for pgsql-hackers@lists.postgresql.org; Fri, 18 Feb 2022 03:00:27 +0000 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nKtVP-0001Lz-TH for pgsql-hackers@postgresql.org; Fri, 18 Feb 2022 03:00:26 +0000 Received: by mail-io1-xd2a.google.com with SMTP id z2so6051074iow.8 for ; Thu, 17 Feb 2022 19:00:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=CtC+8JU97bsRte8MkdKQMZnUGo0XkkkU45o0g9F2fc8=; b=hXXWisudP4GyQyhlED5aExJZ2FfGMBJtB8qj60P+adzsyHF+PEuHdW4pwLkHb+hkcm vMTn/ngwalKZvzY9/ebBm4Usqx6y1fK/KyNFuC3VKFRlJ/LjSoy3s8H8OyJj3J4M8ZsC caiWLbuGfP+VrgWE3Zshto0mHTman9wgtkH1nV4Axx+KZGufE2D+4KZ9in4KkZjVk+Zl lQMDPCZkcQjLxcVBN2kQpC9duMsnABhC5BVOz3zrW5oWnCePr9aWgIpFYgh0kKadMlJP fnIjsA4VB91vw+vp4w/dIkNCtQizvw3wj2XK59pYRpuXkfRS0IqbJrqt1KcGYUobZisv S55g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=CtC+8JU97bsRte8MkdKQMZnUGo0XkkkU45o0g9F2fc8=; b=TrypZP1nuEPFGwKubP37wsfA92vBbpG3Js91qoRn6dc9ryWdmsJg5XwwJnFlZQehPJ aPIrcIYJXjj3kaHLEdY1cHUsE08wPUKMR88dpebSxn2SqlSGvnOiuLtqNTXp8mQsafUu 1Qm2WV6u67oOfwCAOUQzCr33UYKk1lz8mM2GQ6bFGJ83L6r0Lz6vNGz0JSjLpaF43Vds fVmQteUUTSS6DeZTiHhBam1vX7CCv75yagYWpaeIA6h4qj2iyWVbU/JuGbZsMlS6ND42 7pE9i3/HKGreMsKNoZhltxUD3Lf/F5NoySK9jgoiRCt3bRUJOhVAOWwdTnD77PhtWfu6 nPNA== X-Gm-Message-State: AOAM532ZgjIT/bLeGweZP3Bwx8+uonxYkwPTPH3luVN9EPRGFHKU/RMJ Id/1UxvjS/9210VScGyY7Zh8t3EMkzJuuA== X-Google-Smtp-Source: ABdhPJzJuTXrMkqiDN6F8WscenyZSE4lsfBI/U804Cdml2nQm5F0ixW72BoUjsfi30ZsEw9WhynAbA== X-Received: by 2002:a6b:7f45:0:b0:5ed:686c:7807 with SMTP id m5-20020a6b7f45000000b005ed686c7807mr4096887ioq.191.1645153221851; Thu, 17 Feb 2022 19:00:21 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id k9sm2931309ilv.31.2022.02.17.19.00.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Feb 2022 19:00:21 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id C7BDE800C82; Thu, 17 Feb 2022 21:00:20 -0600 (CST) Date: Thu, 17 Feb 2022 21:00:20 -0600 From: Justin Pryzby To: Daria Lepikhova Cc: pgsql-hackers@postgresql.org Subject: Re: Assert in pageinspect with NULL pages Message-ID: <20220218030020.GA1137@telsasoft.com> References: <561e187b-3549-c8d5-03f5-525c14e65bd0@postgrespro.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <561e187b-3549-c8d5-03f5-525c14e65bd0@postgrespro.ru> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk BRIN can also crash if passed a non-brin index. I've been sitting on this one for awhile. Feel free to include it in your patchset. commit 08010a6037fc4e24a9ba05e5386e766f4310d35e Author: Justin Pryzby Date: Tue Jan 19 00:25:15 2021 -0600 pageinspect: brin_page_items(): check that given relation is not only an index, but a brin one diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c index f1e64a39ef2..3de6dd943ef 100644 --- a/contrib/pageinspect/brinfuncs.c +++ b/contrib/pageinspect/brinfuncs.c @@ -16,6 +16,7 @@ #include "access/brin_tuple.h" #include "access/htup_details.h" #include "catalog/index.h" +#include "catalog/pg_am.h" #include "catalog/pg_type.h" #include "funcapi.h" #include "lib/stringinfo.h" @@ -59,7 +60,7 @@ brin_page_type(PG_FUNCTION_ARGS) if (raw_page_size != BLCKSZ) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("input page too small"), + errmsg("input page wrong size"), errdetail("Expected size %d, got %d", BLCKSZ, raw_page_size))); @@ -97,7 +98,7 @@ verify_brin_page(bytea *raw_page, uint16 type, const char *strtype) if (raw_page_size != BLCKSZ) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("input page too small"), + errmsg("input page wrong size"), errdetail("Expected size %d, got %d", BLCKSZ, raw_page_size))); @@ -169,7 +170,14 @@ brin_page_items(PG_FUNCTION_ARGS) MemoryContextSwitchTo(oldcontext); indexRel = index_open(indexRelid, AccessShareLock); - bdesc = brin_build_desc(indexRel); + + /* Must be a BRIN index */ + if (indexRel->rd_rel->relkind != RELKIND_INDEX || + indexRel->rd_rel->relam != BRIN_AM_OID) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("\"%s\" is not a BRIN index", + RelationGetRelationName(indexRel)))); /* minimally verify the page we got */ page = verify_brin_page(raw_page, BRIN_PAGETYPE_REGULAR, "regular"); @@ -178,6 +186,7 @@ brin_page_items(PG_FUNCTION_ARGS) * Initialize output functions for all indexed datatypes; simplifies * calling them later. */ + bdesc = brin_build_desc(indexRel); columns = palloc(sizeof(brin_column_state *) * RelationGetDescr(indexRel)->natts); for (attno = 1; attno <= bdesc->bd_tupdesc->natts; attno++) {