]> granicus.if.org Git - postgresql/commitdiff
Fix broken error check in _hash_doinsert.
authorRobert Haas <rhaas@postgresql.org>
Thu, 22 Dec 2016 18:54:40 +0000 (13:54 -0500)
committerRobert Haas <rhaas@postgresql.org>
Thu, 22 Dec 2016 19:15:52 +0000 (14:15 -0500)
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

index 66084f4a6fcd6b45acf4f110c523d5f97203c7e0..9ce4c1860883cb89bf1439106a4d8130f06a5f46 100644 (file)
@@ -32,6 +32,7 @@ _hash_doinsert(Relation rel, IndexTuple itup)
        Buffer          metabuf;
        HashMetaPage metap;
        BlockNumber blkno;
+       Page            metapage;
        Page            page;
        HashPageOpaque pageopaque;
        Size            itemsz;
@@ -57,7 +58,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
@@ -66,12 +68,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.")));
 
        /*