BUG #19904: pg_column_is_updatable(): "negative bitmapset member not allowed" for large attnum (int16 overflow)

Поиск
Список
Период
Сортировка
Искать

BUG #19904: pg_column_is_updatable(): "negative bitmapset member not allowed" for large attnum (int16 overflow)

От:
PG Bug reporting form <noreply@postgresql.org>
Дата:
The following bug has been logged on the website:

Bug reference:      19904
Logged by:          Zheng Hacker
Email address:      hackerzheng666@gmail.com
PostgreSQL version: 19rc2
Operating system:   Linux x86_64 (Ubuntu 22.04)
Description:        

Tested on git master (20devel, commit 70c4a57b64d3; the code in question is
unchanged at master 81b2179 as of 2026-11-14). Not tested on 19rc2 or older
branches; the version selected in the form is only the closest listed one.

create table tt(a int, b text);
select pg_column_is_updatable('tt'::regclass, 32767::smallint, true);
ERROR:  negative bitmapset member not allowed

In src/backend/utils/adt/misc.c, pg_column_is_updatable() computes

    AttrNumber  col = attnum - FirstLowInvalidHeapAttributeNumber;

AttrNumber is int16, FirstLowInvalidHeapAttributeNumber is -7, so for attnum
>= 32761 the result wraps to a negative value and bms_make_singleton(col)
raises the internal error. A valid table with a nonexistent column number
should simply return false, not an internal error. Computing col as int (or
returning false when attnum exceeds the relation's column count before
building the bitmapset) avoids it.




Re: BUG #19904: pg_column_is_updatable(): "negative bitmapset member not allowed" for large attnum (int16 overflow)

От:
David Rowley <dgrowleyml@gmail.com>
Дата:
On Tue, 17 Nov 2026 at 00:45, PG Bug reporting form
 wrote:
> create table tt(a int, b text);
> select pg_column_is_updatable('tt'::regclass, 32767::smallint, true);
> ERROR:  negative bitmapset member not allowed

So don't do that?

We could fix by just promoting the AttrNumber to int with:

--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -639,7 +639,7 @@ pg_column_is_updatable(PG_FUNCTION_ARGS)
 {
        Oid                     reloid = PG_GETARG_OID(0);
        AttrNumber      attnum = PG_GETARG_INT16(1);
-       AttrNumber      col = attnum - FirstLowInvalidHeapAttributeNumber;
+       int                     col = attnum -
FirstLowInvalidHeapAttributeNumber;
        bool            include_triggers = PG_GETARG_BOOL(2);

That avoids overflowing the int16 when subtracting the -7

David


Re: BUG #19904: pg_column_is_updatable(): "negative bitmapset member not allowed" for large attnum (int16 overflow)

От:
David Rowley <dgrowleyml@gmail.com>
Дата:
On Tue, 17 Nov 2026 at 16:55, David Rowley  wrote:
>
> On Tue, 17 Nov 2026 at 00:45, PG Bug reporting form
>  wrote:
> > create table tt(a int, b text);
> > select pg_column_is_updatable('tt'::regclass, 32767::smallint, true);
> > ERROR:  negative bitmapset member not allowed
>
> We could fix by just promoting the AttrNumber to int with:

Pushed. Thanks.

David


FAQ