pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18875: COPY BINARY tsvector FROM file leads to misaligned memory access
Date: Wed, 02 Apr 2025 15:45:14 -0400
Message-ID: <1121363.1743623114@sss.pgh.pa.us> (raw)
In-Reply-To: <18875-07a29c49c825a608@postgresql.org>
References: <18875-07a29c49c825a608@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> The following script, executed against a build with sanitizers enabled:
> CREATE TABLE test_tsvector(t text, a tsvector);
> COPY test_tsvector FROM '.../src/test/regress/data/tsearch.data';
> COPY BINARY test_tsvector TO '/tmp/t.data';
> COPY BINARY test_tsvector FROM '/tmp/t.data';

> triggers a runtime error:
> 2025-04-02 17:23:25.502 UTC [1721608] LOG:  statement: COPY BINARY
> test_tsvector FROM '/tmp/t.data';
> tsvector.c:90:59: runtime error: member access within misaligned address
> 0x52500005a23c for type 'const struct WordEntryIN', which requires 8 byte
> alignment

Hmm.  This is evidently because of the type pun involved: WordEntryCMP
is supposed to compare WordEntry structs, but it's turning around and
using compareentry which compares WordEntryIN structs.  And those are
larger/better aligned.  Now compareentry doesn't access anything
outside the WordEntry part, but it's theoretically possible that
the compiler could generate load instructions that depend on the
larger alignment.  Given the lack of field reports, that's not
happening on any platforms where it would matter.  But still we
ought to clean it up.

ISTM this coding is basically backwards: compareentry should be coded
to work on WordEntry structs, and then if it's used to compare
WordEntry structs that are embedded in WordEntryIN there's no problem.
And then we don't need the WordEntryCMP wrapper at all.

Will fix, thanks for the report!

			regards, tom lane





view thread (2+ messages)

Message-ID: <1121363.1743623114@sss.pgh.pa.us>
Permalink:  ../1121363.1743623114@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1121363.1743623114@sss.pgh.pa.us

 · 

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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18875: COPY BINARY tsvector FROM file leads to misaligned memory access
  In-Reply-To: <1121363.1743623114@sss.pgh.pa.us>

* 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