BUG #19905: loread() with length near INT_MAX: "invalid memory alloc request size" (int32 overflow)

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: hackerzheng666(at)gmail(dot)com
Subject: BUG #19905: loread() with length near INT_MAX: "invalid memory alloc request size" (int32 overflow)
Date: 2026-11-15 04:49:11
Message-ID: 19905-3f33374cbee82db1@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19905
Logged by: Zheng Hacker
Email address: hackerzheng666(at)gmail(dot)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.

select loread(2147483647, 2147483647);
ERROR: invalid memory alloc request size 18446744071562067971

In src/backend/libpq/be-fsstubs.c, be_loread() (the SQL function loread)
does

retval = (bytea *) palloc(VARHDRSZ + len);

with "int len". For len > INT_MAX - VARHDRSZ the sum overflows to a negative
int and is converted to a huge size_t, so the user sees an internal-looking
error with a nonsensical size instead of a clean limit error. Clamping len
to MaxAllocSize - VARHDRSZ (or raising "requested length too large" before
the allocation, as lo_get() style paths do) would give a proper message.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message shihao zhong 2026-11-15 05:02:01 Re: BUG #19816: PL/Python SD dictionary is split by input collation in 19rc1
Previous Message PG Bug reporting form 2026-11-15 04:48:38 BUG #19904: pg_column_is_updatable(): "negative bitmapset member not allowed" for large attnum (int16 overflow)