pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid faulty alignment of Datums in build_sorted_items().
Date: Wed, 10 Sep 2025 21:51:31 +0000
Message-ID: <E1uwSix-0004y4-1L@gemulon.postgresql.org> (raw)

Avoid faulty alignment of Datums in build_sorted_items().

If sizeof(Pointer) is 4 then sizeof(SortItem) will be 12, so that
if data->numrows is odd then we placed the values array at a location
that's not a multiple of 8.  That was fine when sizeof(Datum) was also
4, but in the wake of commit 2a600a93c it makes some alignment-picky
machines unhappy.  (You need a 32-bit machine that nonetheless expects
8-byte alignment of 8-byte quantities, which is an odd-seeming
combination but it does exist outside the Intel universe.)

To fix, MAXALIGN the space allocated to the SortItem array.
In passing, let's make the "len" variable be Size not int,
just for paranoia's sake.

This code was arguably not too safe even before 2a600a93c, but at
present I don't see a strong argument for back-patching.

Reported-by: Tomas Vondra <tomas@vondra.me>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/87036018-8d70-40ad-a0ac-192b07bd7b04@vondra.me

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/09036dc71c682b0bf7234ed39c1429ed99fbe442

Modified Files
--------------
src/backend/statistics/extended_stats.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)



Message-ID: <E1uwSix-0004y4-1L@gemulon.postgresql.org>
Permalink:  ../E1uwSix-0004y4-1L@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1uwSix-0004y4-1L@gemulon.postgresql.org

 · 

reply

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-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Avoid faulty alignment of Datums in build_sorted_items().
  In-Reply-To: <E1uwSix-0004y4-1L@gemulon.postgresql.org>

* 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