Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wp8UL-001S17-1x for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Jul 2026 17:54:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wp8UJ-007TQk-2D for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Jul 2026 17:54:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wp8IE-007RuG-1r for pgsql-bugs@lists.postgresql.org; Wed, 29 Jul 2026 17:42:10 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wp8IA-00000000xM4-1Iq8 for pgsql-bugs@lists.postgresql.org; Wed, 29 Jul 2026 17:42:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=XgyVL8jcZhRHuh3FjW3/YsJCbL5SHWJhOcq6sZGh4KI=; b=PavNQxoeNcSh5j3zZBVuI+IVWX GR/mTgDij62hRC+tWTGYgHdzxnrKBK8uC+iSWxcj1LNDP/gKxZx+9hiyWTTriwcmJJ/gkZhxrl5eO Fm90etiD5jEEycLGGOml2FQTVbC34Bi2wnKfZBuG9GM6gCqQsxCKgwagnlMLY11gK/u7BznGQwgkZ xt19ma0+VFUctkTLzZdIk4NPMD6ElI0Od59+/tC1LDz86FBN2bw0LvIX2fTd4Nc59nfVd9DIVUdgh t7uNRBdvar/1dxYOA+uFxF7FZGF5EaeXtY02v/xCvKfeRr5qgVBMoTtVL+m4wkInJ1wfbO3Zbv+5L NNj/A4fw==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wp8I8-002xFl-2B for pgsql-bugs@lists.postgresql.org; Wed, 29 Jul 2026 17:42:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1wp8I7-00000006x0L-2YNl for pgsql-bugs@lists.postgresql.org; Wed, 29 Jul 2026 17:42:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19586: money division overflow To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: malis@pgrust.com Reply-To: malis@pgrust.com, pgsql-bugs@lists.postgresql.org Date: Wed, 29 Jul 2026 17:41:53 +0000 Message-ID: <19586-bb603bf5ad9934dd@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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: =20 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 =3D=3D 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.