Re: Bus error in pg_logical_slot_get_changes (9.4.7, sparc)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Christoph Berg <myon(at)debian(dot)org>
Cc: Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Bus error in pg_logical_slot_get_changes (9.4.7, sparc)
Date: 2016-04-14 17:11:43
Message-ID: 423.1460653903@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Christoph Berg <myon(at)debian(dot)org> writes:
>> ... the patch worked indeed, thanks!

> Duh, the patch does work on sparc, but it breaks amd64:

Well, yeah, because if Size is wider than int32 then that memcpy isn't
enough to initialize it.

But looking around a bit, I think that ReorderBufferRestoreChange is
almost completely broken on alignment-picky machines, if the expectation
is that the input data could be aligned arbitrarily. Aside from this
particular problem, it contains multiple places where we cast "data"
to something other than char*, and that is sufficient to allow a
spec-compliant compiler to decide that "data" is aligned on more than
a char boundary and hence generate code that depends on such alignment.

I also noticed that the INTERNAL_SNAPSHOT case doesn't bother to advance
"data" past the data read, where all the other switch cases do. In the
attached, I made it do likewise, but it looks like you could equally
easily just drop the final update of "data" in each switch case,
because nothing is looking at it after the switch.

Proposed patch attached, but I'm still wondering why the alignment-picky
buildfarm members aren't all failing on this. It seems to strongly
suggest that the regression tests' coverage is lacking here.

regards, tom lane

Attachment Content-Type Size
alignment-fixup.patch text/x-diff 3.6 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Christoph Berg 2016-04-14 18:36:02 Re: Bus error in pg_logical_slot_get_changes (9.4.7, sparc)
Previous Message Fujii Masao 2016-04-14 14:41:30 Re: 9.6 synchronous_standby_names: discrepancy between docs and functionality