Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u041X-00AsEA-Vc for pgsql-bugs@arkaria.postgresql.org; Wed, 02 Apr 2025 19:45:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u041W-00HXTs-JD for pgsql-bugs@arkaria.postgresql.org; Wed, 02 Apr 2025 19:45:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u041W-00HXTi-At for pgsql-bugs@lists.postgresql.org; Wed, 02 Apr 2025 19:45:18 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u041U-0031kW-0Q for pgsql-bugs@lists.postgresql.org; Wed, 02 Apr 2025 19:45:17 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 532JjE0C1121364; Wed, 2 Apr 2025 15:45:14 -0400 From: Tom Lane To: exclusion@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18875: COPY BINARY tsvector FROM file leads to misaligned memory access In-reply-to: <18875-07a29c49c825a608@postgresql.org> References: <18875-07a29c49c825a608@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 02 Apr 2025 19:00:02 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1121362.1743623114.1@sss.pgh.pa.us> Date: Wed, 02 Apr 2025 15:45:14 -0400 Message-ID: <1121363.1743623114@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form 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