1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

In pageinspect/hashfuncs.c, avoid crashes on alignment-picky machines.

On machines with MAXALIGN = 8, the payload of a bytea is not maxaligned,
since it will start 4 bytes into a palloc'd value.  On alignment-picky
hardware, this will cause failures in accesses to 8-byte-wide values
within the page.  We already encountered this problem when we introduced
GIN index inspection functions, and fixed it in commit 84ad68d64.  Make
use of the same function for hash indexes.

A small difficulty is that up to now contrib/pageinspect has not shared
any functions at all across files.  To support that, introduce a common
header file "pageinspect.h" for the module.

Also, move get_page_from_raw() out of ginfuncs.c, where it didn't
especially belong, and put it in rawpage.c which seems a more natural home.

Per buildfarm.

Discussion: https://postgr.es/m/17311.1486134714@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2017-02-03 11:34:41 -05:00
parent 29e312bc13
commit 14e9b18fed
8 changed files with 73 additions and 34 deletions

View File

@ -10,6 +10,8 @@
#include "postgres.h"
#include "pageinspect.h"
#include "access/hash.h"
#include "access/htup_details.h"
#include "catalog/pg_type.h"
@ -48,27 +50,15 @@ typedef struct HashPageStat
/*
* Verify that the given bytea contains a HASH page, or die in the attempt.
* A pointer to the page is returned.
* A pointer to a palloc'd, properly aligned copy of the page is returned.
*/
static Page
verify_hash_page(bytea *raw_page, int flags)
{
Page page;
int raw_page_size;
Page page = get_page_from_raw(raw_page);
int pagetype;
HashPageOpaque pageopaque;
raw_page_size = VARSIZE(raw_page) - VARHDRSZ;
if (raw_page_size != BLCKSZ)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid page size"),
errdetail("Expected size %d, got %d",
BLCKSZ, raw_page_size)));
page = VARDATA(raw_page);
if (PageIsNew(page))
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),