pgsql: Improve error message for to lrage LO read requests

From: Daniel Gustafsson <dgustafsson(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Improve error message for to lrage LO read requests
Date: 2026-11-19 09:16:20
Message-ID: E1xTyFf-00000000MV5-19gK@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Improve error message for to lrage LO read requests

Calling loread() with a length argument which exceeds the max
allocation yields an invalid memory alloc error message, and
if the length overflows it will be a nonsensical value which
can be confusing.

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

Fix by detecting an oversize length request and error out like
how other LO read functions do. The error message is identical
to already existing messages to avoid new translation work.

This is not backpatched as the current behavior is safe, this
is only an improvement in the messaging.

Author: Daniel Gustafsson <daniel(at)yesql(dot)se>
Reported-by: Zheng Hacker <hackerzheng666(at)gmail(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/19905-3f33374cbee82db1@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2c077c7d602dba034e209227ea04a14b10797c42

Modified Files
--------------
src/backend/libpq/be-fsstubs.c | 5 +++++
1 file changed, 5 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-11-19 10:37:02 pgsql: Fix incorrect pointer increment in pgtypes_defmt_scan()
Previous Message Fujii Masao 2026-11-19 07:12:17 pgsql: Fix pg_combinebackup handling of intermediate truncations