agora inbox for pgsql-bugs@postgresql.org
help / color / mirror / Atom feedBUG #19586: money division overflow
2+ messages / 2 participants
[nested] [flat]
* BUG #19586: money division overflow
@ 2026-07-29 17:41 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 2+ messages in thread
From: PG Bug reporting form @ 2026-07-29 17:41 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: malis@pgrust.com
The following bug has been logged on the website:
Bug reference: 19586
Logged by: Michael Malis
Email address: malis@pgrust.com
PostgreSQL version: 18.4
Operating system: Linux x86_64 and Linux aarch64
Description:
cash_div_int64() in src/backend/utils/adt/cash.c guards against division by
zero but not against the INT64_MIN / -1 overflow:
cash_div_int64(Cash c, int64 i)
{
if (unlikely(i == 0))
ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), ...));
return c / i;
}
Commit 4f96281587 ("Add overflow checks to money type", 2024-07-19, fixing
bug
#18240) added pg_mul_s64_overflow() checks to cash_mul_int64() and the
float paths, but the division path was not covered.
Steps to reproduce
SELECT '-92233720368547758.08'::money / -1;
Actual results
On x86-64, the hardware division trap is caught by PostgreSQL's SIGFPE
handler and surfaces as a misleading error class for an integer overflow:
ERROR: floating-point exception
DETAIL: An invalid floating-point operation was signaled...
On aarch64, where the division does not trap, the wrong value is returned
silently, with no error:
-$92,233,720,368,547,758.08
i.e. a negative value divided by -1 remains negative.
Expected results
The same treatment int8div() already gives the identical arithmetic, on
every platform:
SELECT (-9223372036854775808)::bigint / -1;
ERROR: bigint out of range
Multiplication in the money type is already guarded and behaves correctly:
SELECT '-92233720368547758.08'::money * -1;
ERROR: money out of range
I would be happy to provide a patch.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #19586: money division overflow
@ 2026-08-04 06:02 David Rowley <dgrowleyml@gmail.com>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 0 replies; 2+ messages in thread
From: David Rowley @ 2026-08-04 06:02 UTC (permalink / raw)
To: Andrey Rachitskiy <pl0h0yp1@gmail.com>; +Cc: malis@pgrust.com; pgsql-bugs@lists.postgresql.org
On Thu, 30 Jul 2026 at 13:40, Andrey Rachitskiy <pl0h0yp1@gmail.com> wrote:
> Thanks for the report.
> Patch attached.
Thanks. Pushed.
David
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-08-04 06:02 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-07-29 17:41 BUG #19586: money division overflow PG Bug reporting form <noreply@postgresql.org>
2026-08-04 06:02 ` David Rowley <dgrowleyml@gmail.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox