Re: Undefined behavior detected by new clang's ubsan

From: John Naylor <johncnaylorls(at)gmail(dot)com>
To: Alexander Lakhin <exclusion(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Undefined behavior detected by new clang's ubsan
Date: 2026-01-22 05:14:17
Message-ID: CANWCAZaM6h4saSOYo__5-G4X6xT=FTq1HabEyNM+nmLe3GnyLQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 22, 2026 at 3:00 AM Alexander Lakhin <exclusion(at)gmail(dot)com> wrote:
> 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

Okay, I'll refrain from guessing more then. I'm due for an OS upgrade
anyway, and that'll have clang 21, so I'll come back to this one
unless someone beats me to it.

--
John Naylor
Amazon Web Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Shinya Kato 2026-01-22 05:34:34 Avoid recalculating pgprocno in ProcArrayAdd()
Previous Message Xuneng Zhou 2026-01-22 04:37:42 Re: Add WALRCV_CONNECTING state to walreceiver