Re: Remove dependence on integer wrapping

From: Joseph Koshakow <koshy44(at)gmail(dot)com>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, Alexander Lakhin <exclusion(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Remove dependence on integer wrapping
Date: 2024-07-22 22:56:14
Message-ID: CAAvxfHeg0En5VV_9pjoHgd0kerK7REL84XEiS6=PUDOSKwx9rg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jul 22, 2024 at 6:27 PM Nathan Bossart <nathandbossart(at)gmail(dot)com>
wrote:
>
> Actually, I think my concerns about prohibiting more than necessary go
away
> if we do the subtraction first. If "upperIndx[i] - lowerIndx[i]"
> overflows, we know the array size is too big. Similarly, if adding one to
> that result overflows, we again know the the array size is too big. This
> appears to be how the surrounding code handles this problem (e.g.,
> ReadArrayDimensions()). Thoughts?

I like that approach! It won't reject any valid bounds and is
consistent with the surrounding code. Also statements of the following
format will maintain the same error messages they had previously:

# INSERT INTO arroverflowtest(i[2147483646:2147483647]) VALUES
('{1,2}');
ERROR: array lower bound is too large: 2147483646

The specific bug that this patch fixes is preventing the following
statement:

# INSERT INTO arroverflowtest(i[-2147483648:2147483647]) VALUES ('{1}');

So we may want to add that test back in.

Thanks,
Joseph Koshakow

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2024-07-22 23:03:37 Re: pg_upgrade and logical replication
Previous Message Tom Lane 2024-07-22 22:43:41 Re: [PATCH] GROUP BY ALL