diff options
author | Tom Lane | 2025-03-27 17:20:23 +0000 |
---|---|---|
committer | Tom Lane | 2025-03-27 17:20:23 +0000 |
commit | 4623d71443de40781135a7040079ab4538974a6f (patch) | |
tree | d30b5423a5984b0b808762a36e93b9431bc07a21 /contrib | |
parent | d66997dfe8fe5a2fc6e25a64e78309ca2094f396 (diff) |
Prevent assertion failure in contrib/pg_freespacemap.
Applying pg_freespacemap() to a relation lacking storage (such as a
view) caused an assertion failure, although there was no ill effect
in non-assert builds. Add an error check for that case.
Bug: #18866
Reported-by: Robins Tharakan <[email protected]>
Author: Tender Wang <[email protected]>
Reviewed-by: Euler Taveira <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 13
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/pg_freespacemap/pg_freespacemap.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/contrib/pg_freespacemap/pg_freespacemap.c b/contrib/pg_freespacemap/pg_freespacemap.c index c0eac7a2016..610fc90b5ba 100644 --- a/contrib/pg_freespacemap/pg_freespacemap.c +++ b/contrib/pg_freespacemap/pg_freespacemap.c @@ -11,6 +11,7 @@ #include "access/relation.h" #include "fmgr.h" #include "storage/freespace.h" +#include "utils/rel.h" PG_MODULE_MAGIC_EXT( .name = "pg_freespacemap", @@ -33,6 +34,13 @@ pg_freespace(PG_FUNCTION_ARGS) rel = relation_open(relid, AccessShareLock); + if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind)) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("relation \"%s\" does not have storage", + RelationGetRelationName(rel)), + errdetail_relkind_not_supported(rel->rd_rel->relkind))); + if (blkno < 0 || blkno > MaxBlockNumber) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |