From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: hackerzheng666@gmail.com
Subject: BUG #19905: loread() with length near INT_MAX: "invalid memory alloc request size" (int32 overflow)
Date: Sun, 15 Nov 2026 04:49:11 +0000
Message-ID: <19905-3f33374cbee82db1@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 19905
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.
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, hackerzheng666@gmail.com
Subject: Re: BUG #19905: loread() with length near INT_MAX: "invalid memory alloc request size" (int32 overflow)
In-Reply-To: <19905-3f33374cbee82db1@postgresql.org>
References: <19905-3f33374cbee82db1@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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