]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix missing money overflow checks for INT64_MIN / -1
authorDavid Rowley <drowley@postgresql.org>
Tue, 4 Aug 2026 05:59:13 +0000 (17:59 +1200)
committerDavid Rowley <drowley@postgresql.org>
Tue, 4 Aug 2026 05:59:13 +0000 (17:59 +1200)
commitb4dfae2ffac25ea6caf116091b5ed15e140ddfc0
tree897c4eaab68faefb2c2a62ac92010e560408a748
parent03f420c37f898b817d24ee6af55eb5e41ec51655
Fix missing money overflow checks for INT64_MIN / -1

Similar to what 1f7cb5c30 did for the INT types, protect against
overflow when dividing the lowest possible money value by -1.  This
cannot be represented on a two's complement machine.

Without this check, the result depends on the machine, and in the worst
case, could result in a crash.  With the fix installed, this will now
result in:

ERROR:  money out of range

Bug: #19585
Author: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Reported-by: Michael Malis <malis@pgrust.com>
Reviewed-by: Tristan Partin <tristan@partin.io>
Reviewed-by: Rafia Sabih <rafia.pghackers@gmail.com>
Discussion: https://postgr.es/m/19586-bb603bf5ad9934dd%40postgresql.org
Discussion: https://postgr.es/m/CAB8bMisnXJVXte6s3kUOpuuAY9%3D9kehG6MMX-%2BTQoFsSGan22Q%40mail.gmail.com
Backpatch-through: 14
src/backend/utils/adt/cash.c
src/test/regress/expected/money.out
src/test/regress/sql/money.sql