From: Alexander Lakhin <exclusion@gmail.com>
To: John Naylor <johncnaylorls@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Subject: Re: Undefined behavior detected by new clang's ubsan
Date: Wed, 21 Jan 2026 22:00:00 +0200
Message-ID: <ba2ba16a-13bd-4d66-8ce5-753792d7a4ff@gmail.com> (raw)
In-Reply-To: <CANWCAZZLjknosPdfZHsQmb_Et8kRZQFsp1gjfr+6=2o9Xsh6qA@mail.gmail.com>
References: <777bd201-6e3a-4da0-a922-4ea9de46a3ee@gmail.com>
<CANWCAZbm1cZyNAmV+f-GBD3pa3F=Nx6x85mH-c4eS=-2us3OjQ@mail.gmail.com>
<7ea15f17-f001-4b5c-979d-b9cff4db46bb@gmail.com>
<CANWCAZZWvds_35nXc4vXD-eBQa_=mxVtqZf-PM_ps=SD7ghhJg@mail.gmail.com>
<1710697.1768935128@sss.pgh.pa.us>
<CANWCAZZLjknosPdfZHsQmb_Et8kRZQFsp1gjfr+6=2o9Xsh6qA@mail.gmail.com>
Hello John,
21.01.2026 12:05, John Naylor wrote:
> As for the rest of the proposed fixes, most seem okay, but I have some nits:
Thank you for spending time on this!
I agree with all of your changes (except for one noted below) -- didn't
mean to propose committable changes, just wanted to show the fixes that
allowed check-world to pass.
> heaptoast.c
> memcpy(VARDATA(result) +
> - (curchunk * TOAST_MAX_CHUNK_SIZE - sliceoffset) + chcpystrt,
> + (int)(curchunk * TOAST_MAX_CHUNK_SIZE - sliceoffset) + chcpystrt,
>
> Not sure about this one. It would be better if we reversing the
> operands allowed us to avoid overflow in the first place:
>
> - (curchunk * TOAST_MAX_CHUNK_SIZE - sliceoffset) + chcpystrt,
> + chcpystrt + (curchunk * TOAST_MAX_CHUNK_SIZE - sliceoffset)
>
> Does that silence the warning?
Unfortunately, no -- I still got:
heaptoast.c:771:17: runtime error: addition of unsigned offset to 0x78120673fac6 overflowed to 0x78120673fa04
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior heaptoast.c:771:17
Best regards,
Alexander
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: exclusion@gmail.com, johncnaylorls@gmail.com, tgl@sss.pgh.pa.us
Subject: Re: Undefined behavior detected by new clang's ubsan
In-Reply-To: <ba2ba16a-13bd-4d66-8ce5-753792d7a4ff@gmail.com>
References: <777bd201-6e3a-4da0-a922-4ea9de46a3ee@gmail.com> <CANWCAZbm1cZyNAmV+f-GBD3pa3F=Nx6x85mH-c4eS=-2us3OjQ@mail.gmail.com> <7ea15f17-f001-4b5c-979d-b9cff4db46bb@gmail.com> <CANWCAZZWvds_35nXc4vXD-eBQa_=mxVtqZf-PM_ps=SD7ghhJg@mail.gmail.com> <1710697.1768935128@sss.pgh.pa.us> <CANWCAZZLjknosPdfZHsQmb_Et8kRZQFsp1gjfr+6=2o9Xsh6qA@mail.gmail.com> <ba2ba16a-13bd-4d66-8ce5-753792d7a4ff@gmail.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