Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 17742a0

Browse files
committed
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.
1 parent 51126cc commit 17742a0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/backend/access/hash/hashinsert.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ _hash_doinsert(Relation rel, IndexTuple itup)
3434
BlockNumber blkno;
3535
BlockNumber oldblkno = InvalidBlockNumber;
3636
bool retry = false;
37+
Page metapage;
3738
Page page;
3839
HashPageOpaque pageopaque;
3940
Size itemsz;
@@ -53,7 +54,8 @@ _hash_doinsert(Relation rel, IndexTuple itup)
5354

5455
/* Read the metapage */
5556
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE);
56-
metap = HashPageGetMeta(BufferGetPage(metabuf));
57+
metapage = BufferGetPage(metabuf);
58+
metap = HashPageGetMeta(metapage);
5759

5860
/*
5961
* Check whether the item can fit on a hash page at all. (Eventually, we
@@ -62,11 +64,11 @@ _hash_doinsert(Relation rel, IndexTuple itup)
6264
*
6365
* XXX this is useless code if we are only storing hash keys.
6466
*/
65-
if (itemsz > HashMaxItemSize((Page) metap))
67+
if (itemsz > HashMaxItemSize(metapage))
6668
ereport(ERROR,
6769
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
6870
errmsg("index row size %zu exceeds hash maximum %zu",
69-
itemsz, HashMaxItemSize((Page) metap)),
71+
itemsz, HashMaxItemSize(metapage)),
7072
errhint("Values larger than a buffer page cannot be indexed.")));
7173

7274
/*

0 commit comments

Comments
 (0)