BUG #19836: Backend crash with large hash partition modulus
The following bug has been logged on the website:
Bug reference: 19836
Logged by: Sumedh Pathak
Email address: sumedhpathak@gmail.com
PostgreSQL version: 19rc1
Operating system: MacOS
Description:
Hi,
The following SQL crashes PostgreSQL 20devel (72b9498df9a, macOS ARM64):
CREATE TABLE parent (i integer) PARTITION BY HASH (i);
CREATE TABLE p0 PARTITION OF parent
FOR VALUES WITH (MODULUS 3, REMAINDER 0);
CREATE TABLE p1 PARTITION OF parent
FOR VALUES WITH (MODULUS 2147483646, REMAINDER 2);
The third statement causes a crash and server recovery. In
check_new_partition_bound(), remainder += spec->modulus overflows signed int
(2 + 2147483646), leading to an out-of-bounds lookup. The crash was verified
on PG 17,18 as well, but it seems like it exists since PG11.
Thanks.
On Sun, 8 Nov 2026 at 04:54, PG Bug reporting form
<noreply@postgresql.org> wrote:
The following SQL crashes PostgreSQL 20devel (72b9498df9a, macOS ARM64):
CREATE TABLE parent (i integer) PARTITION BY HASH (i);
CREATE TABLE p0 PARTITION OF parent
FOR VALUES WITH (MODULUS 3, REMAINDER 0);
CREATE TABLE p1 PARTITION OF parent
FOR VALUES WITH (MODULUS 2147483646, REMAINDER 2);
Thanks for the report.
It seems fine to just do:
@@ -2919,8 +2919,8 @@ check_new_partition_bound(char *relname, Relation parent,
if (partdesc->nparts > 0)
{
- int
greatest_modulus;
- int remainder;
+ int64 greatest_modulus;
+ int64 remainder;
That'll prevent the wrap and allow the do/while loop to terminate when
remainder is >= greatest_modulus. Bumping greatest_modulus isn't
really required, but I did that because I thought it was neater to
keep them the same size.
I can patch this when the freeze is over.
David
On Mon, 9 Nov 2026 at 13:10, David Rowley <dgrowleyml@gmail.com> wrote:
@@ -2919,8 +2919,8 @@ check_new_partition_bound(char *relname, Relation parent,
if (partdesc->nparts > 0) { - int greatest_modulus; - int remainder; + int64 greatest_modulus; + int64 remainder;That'll prevent the wrap and allow the do/while loop to terminate when
remainder is >= greatest_modulus. Bumping greatest_modulus isn't
really required, but I did that because I thought it was neater to
keep them the same size.I can patch this when the freeze is over.
Pushed.
David