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:
@ -9,6 +9,8 @@
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include "pageinspect.h"
|
||||
|
||||
#include "access/gin.h"
|
||||
#include "access/gin_private.h"
|
||||
#include "access/htup_details.h"
|
||||
@ -29,26 +31,6 @@ PG_FUNCTION_INFO_V1(gin_page_opaque_info);
|
||||
PG_FUNCTION_INFO_V1(gin_leafpage_items);
|
||||
|
||||
|
||||
static Page
|
||||
get_page_from_raw(bytea *raw_page)
|
||||
{
|
||||
int raw_page_size;
|
||||
Page page;
|
||||
|
||||
raw_page_size = VARSIZE(raw_page) - VARHDRSZ;
|
||||
if (raw_page_size < BLCKSZ)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("input page too small (%d bytes)", raw_page_size)));
|
||||
|
||||
/* make a copy so that the page is properly aligned for struct access */
|
||||
page = palloc(raw_page_size);
|
||||
memcpy(page, VARDATA(raw_page), raw_page_size);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
Datum
|
||||
gin_metapage_info(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
Reference in New Issue
Block a user