pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #19898: int4_avg_accum_inv wraps below INT64_MIN instead of raising an error
2+ messages / 2 participants
[nested] [flat]
* BUG #19898: int4_avg_accum_inv wraps below INT64_MIN instead of raising an error
@ 2026-11-12 23:42 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 2+ messages in thread
From: PG Bug reporting form @ 2026-11-12 23:42 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: imchifan8@gmail.com
The following bug has been logged on the website:
Bug reference: 19898
Logged by: Noah
Email address: imchifan8@gmail.com
PostgreSQL version: 18.6
Operating system: Linux/amd64
Description:
pg_catalog.int4_avg_accum_inv silently wraps an inverse-transition sum below
INT64_MIN. Given a reachable state with count 4294967298 and sum INT64_MIN,
removing the input value 1 returns a sum of INT64_MAX instead of reporting
numeric-value-out-of-range.
The state is mathematically reachable by adding 1, then 2^32 copies of
INT32_MIN, then -1. Removing the leading 1 makes the exact next sum
INT64_MIN - 1, which cannot be represented by bigint and should raise an
out-of-range error.
How to repeat:
\set ON_ERROR_STOP on
-- This state is mathematically reachable: +1, followed by 2^32 copies of
-- INT32_MIN, followed by -1, yields count 4294967298 and sum INT64_MIN.
-- Removing the leading +1 makes the exact sum INT64_MIN - 1.
SELECT pg_catalog.int4_avg_accum_inv(
ARRAY[4294967298::bigint, '-9223372036854775808'::bigint],
1::integer) AS inverse_state;
The output was:
inverse_state
----------------------------------
{4294967297,9223372036854775807}
(1 row)
The returned count is reduced by one as expected, but the sum wraps from the
unrepresentable INT64_MIN - 1 result to INT64_MAX.
The issue was reproduced on PostgreSQL 18.6 on Linux/amd64. This occurs when
an int4 moving aggregate removes a value from a reachable state whose exact
next sum is below INT64_MIN.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #19898: int4_avg_accum_inv wraps below INT64_MIN instead of raising an error
@ 2026-11-15 06:54 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-11-15 06:54 UTC (permalink / raw)
To: imchifan8@gmail.com; pgsql-bugs@lists.postgresql.org
On Fri, 13 Nov 2026 at 21:58, PG Bug reporting form
<noreply@postgresql.org> wrote:
> The issue was reproduced on PostgreSQL 18.6 on Linux/amd64. This occurs when
> an int4 moving aggregate removes a value from a reachable state whose exact
> next sum is below INT64_MIN.
Please share a reproducer showing this happening. (I mean specifically
by using the aggregate function, as you mention in the text above, and
not calling the component function manually.)
David
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-11-15 06:54 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 23:42 BUG #19898: int4_avg_accum_inv wraps below INT64_MIN instead of raising an error PG Bug reporting form <noreply@postgresql.org>
2026-11-15 06:54 ` David Rowley <dgrowleyml@gmail.com>
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