From: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Jesper Pedersen <jesper.pedersen@redhat.com>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Ashutosh Sharma <ashu.coek88@gmail.com>
Cc: Jeff Janes <jeff.janes@gmail.com>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: pageinspect: Hash index support
Date: Thu, 3 Nov 2016 11:28:33 -0400
Message-ID: <7351c7bb-db87-be4a-0b86-7f7aad0bed41@2ndquadrant.com> (raw)
In-Reply-To: <8921.1478109287@sss.pgh.pa.us>
References: <e2ac6c58-b93f-9dd9-f4e6-d6d30add7fdf@redhat.com>
<e1bda3f7-dc99-c610-4d48-58815f5b7515@redhat.com>
<CAE9k0P=OQSEj0x9z91tvE9P1f-Ht7x7z8X+eDWQGTJNSFbn9yg@mail.gmail.com>
<5d64a536-cc90-ce96-b68f-5b6bd3206476@redhat.com>
<CAB7nPqTT3ZEm8QKsYYxfUnWL+P3p2mAbud7AFiZpK_JKx3eADA@mail.gmail.com>
<d235dcd6-146a-1269-73a0-da9a55bfeddc@redhat.com>
<80a00b5c-56d3-dffb-8dba-edf5d2167b12@2ndquadrant.com>
<16d89e7e-cb1a-cb5d-e944-6f10c324a312@redhat.com>
<c982b01c-06bc-485b-5dde-057ee244261a@2ndquadrant.com>
<836487ee-8d4e-cd49-54ac-f4793ddba5ae@redhat.com>
<8a751498-6ee9-b943-abf3-b5641851d7de@2ndquadrant.com>
<62ee2eba-3a5b-06d3-e224-cfe00b395be7@redhat.com>
<f52f2117-627b-baa3-1e83-59394e881bf5@2ndquadrant.com>
<f8a19652-c5e4-4b8f-a461-62d886ff2400@2ndquadrant.com>
<66afc31d-e97a-41c3-da4c-bfa02fa2d54e@redhat.com>
<eb68fb02-5a85-e643-11cf-9319dd7edf2b@2ndquadrant.com>
<02dc6cef-a80c-c976-8ac0-518ff9b22dd8@2n! dquadrant.com>
<8921.1478109287@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On 11/2/16 1:54 PM, Tom Lane wrote:
> I think the right thing is likely to be to copy the presented bytea
> into a palloc'd (and therefore properly aligned) buffer. And not
> just in this one function.
Does the attached look reasonable?
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:0001-pageinspect-Fix-unaligned-struct-access-in-GIN-funct.patch (text/x-patch, 2.1K) download
From 086c603016de5018a8baddc88a8932472e0fcd1e Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 3 Nov 2016 12:00:00 -0400
Subject: [PATCH] pageinspect: Fix unaligned struct access in GIN functions
The raw page data that is passed into the functions will not be aligned
at 8-byte boundaries. Casting that to a struct and accessing int64
fields will result in unaligned access. On most platforms, you get away
with it, but it will result on a crash on pickier platforms such as ia64
and sparc64.
---
contrib/pageinspect/ginfuncs.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/contrib/pageinspect/ginfuncs.c b/contrib/pageinspect/ginfuncs.cindex 145e2ce..660d236 100644--- a/contrib/pageinspect/ginfuncs.c+++ b/contrib/pageinspect/ginfuncs.c@@ -51,7 +51,10 @@ gin_metapage_info(PG_FUNCTION_ARGS)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("input page too small (%d bytes)", raw_page_size)));
- page = VARDATA(raw_page);++ /* 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);
opaq = (GinPageOpaque) PageGetSpecialPointer(page);
if (opaq->flags != GIN_META)
@@ -115,7 +118,10 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("input page too small (%d bytes)", raw_page_size)));
- page = VARDATA(raw_page);++ /* 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);
opaq = (GinPageOpaque) PageGetSpecialPointer(page);
@@ -195,7 +201,10 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("input page too small (%d bytes)", raw_page_size)));
- page = VARDATA(raw_page);++ /* 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);
if (PageGetSpecialSize(page) != MAXALIGN(sizeof(GinPageOpaqueData)))
ereport(ERROR,
--
2.10.2
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: peter.eisentraut@2ndquadrant.com, tgl@sss.pgh.pa.us, jesper.pedersen@redhat.com, michael.paquier@gmail.com, ashu.coek88@gmail.com, jeff.janes@gmail.com, alvherre@2ndquadrant.com
Subject: Re: pageinspect: Hash index support
In-Reply-To: <7351c7bb-db87-be4a-0b86-7f7aad0bed41@2ndquadrant.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox