1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-29 10:41:53 +03:00

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.
This commit is contained in:
Robert Haas
2016-12-22 13:54:40 -05:00
parent 44de099f89
commit de651a6e5d

View File

@ -32,6 +32,7 @@ _hash_doinsert(Relation rel, IndexTuple itup)
Buffer metabuf; Buffer metabuf;
HashMetaPage metap; HashMetaPage metap;
BlockNumber blkno; BlockNumber blkno;
Page metapage;
Page page; Page page;
HashPageOpaque pageopaque; HashPageOpaque pageopaque;
Size itemsz; Size itemsz;
@ -57,7 +58,8 @@ _hash_doinsert(Relation rel, IndexTuple itup)
/* Read the metapage */ /* Read the metapage */
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE); 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 * Check whether the item can fit on a hash page at all. (Eventually, we
@ -66,12 +68,12 @@ _hash_doinsert(Relation rel, IndexTuple itup)
* *
* XXX this is useless code if we are only storing hash keys. * XXX this is useless code if we are only storing hash keys.
*/ */
if (itemsz > HashMaxItemSize((Page) metap)) if (itemsz > HashMaxItemSize(metapage))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index row size %lu exceeds hash maximum %lu", errmsg("index row size %lu exceeds hash maximum %lu",
(unsigned long) itemsz, (unsigned long) itemsz,
(unsigned long) HashMaxItemSize((Page) metap)), (unsigned long) HashMaxItemSize(metapage)),
errhint("Values larger than a buffer page cannot be indexed."))); errhint("Values larger than a buffer page cannot be indexed.")));
/* /*