From 603ad8ad298315cab79fa4e1c78095e4a3eca003 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Thu, 22 Dec 2016 13:54:40 -0500 Subject: [PATCH] Fix broken error check in _hash_doinsert. You can't just cast a HashMetaPage to a Page, because the meta page data is stored after the page header, not at offset 0. Fortunately, this didn't break anything because it happens to find hashm_bsize at the offset at which it expects to find pd_pagesize_version, and the values are close enough to the same that this works out. Still, it's a bug, so back-patch to all supported versions. Mithun Cy, revised a bit by me. --- src/backend/access/hash/hashinsert.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/access/hash/hashinsert.c b/src/backend/access/hash/hashinsert.c index 63be2f37872..c8598facd44 100644 --- a/src/backend/access/hash/hashinsert.c +++ b/src/backend/access/hash/hashinsert.c @@ -34,6 +34,7 @@ _hash_doinsert(Relation rel, IndexTuple itup) BlockNumber blkno; BlockNumber oldblkno = InvalidBlockNumber; bool retry = false; + Page metapage; Page page; HashPageOpaque pageopaque; Size itemsz; @@ -53,7 +54,8 @@ _hash_doinsert(Relation rel, IndexTuple itup) /* Read the metapage */ metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE); - metap = HashPageGetMeta(BufferGetPage(metabuf)); + metapage = BufferGetPage(metabuf); + metap = HashPageGetMeta(metapage); /* * Check whether the item can fit on a hash page at all. (Eventually, we @@ -62,12 +64,12 @@ _hash_doinsert(Relation rel, IndexTuple itup) * * XXX this is useless code if we are only storing hash keys. */ - if (itemsz > HashMaxItemSize((Page) metap)) + if (itemsz > HashMaxItemSize(metapage)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("index row size %lu exceeds hash maximum %lu", (unsigned long) itemsz, - (unsigned long) HashMaxItemSize((Page) metap)), + (unsigned long) HashMaxItemSize(metapage)), errhint("Values larger than a buffer page cannot be indexed."))); /* -- 2.30.2