From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: d.kovalenko@postgrespro.ru
Subject: BUG #18896: A potential problem in heap_page_items (pageinspect, PG-17)
Date: Wed, 16 Apr 2025 20:21:16 +0000
Message-ID: <18896-add267b8e06663e3@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 18896
Logged by: Dmitry Kovalenko
Email address: d.kovalenko@postgrespro.ru
PostgreSQL version: 17.4
Operating system: Ubuntu 2024.04
Description:
Hello,
Please, look at this code in heap_page_items function:
https://github.com/postgres/postgres/blob/11ff192b5bb707ba9ec13a0b6c7468874403abb3/contrib/pageinspe...
If lp_len value is less than tuphdr->t_hoff, we get a problem with negative
value in tuple_data_len
I think, we should move the code of /* Copy raw tuple data into bytea
attribute */ into the next if (.... tuphdr->t_hoff <= lp_len ....)
section.
And set nulls[13] = true; to else section here -
https://github.com/postgres/postgres/blob/11ff192b5bb707ba9ec13a0b6c7468874403abb3/contrib/pageinspe...
-------- [copy of problem block at lines 231 ... 248]
/* Copy raw tuple data into bytea attribute */
tuple_data_len = lp_len - tuphdr->t_hoff; // < -----------------
SUBSTRACT
tuple_data_bytea = (bytea *) palloc(tuple_data_len + VARHDRSZ);
SET_VARSIZE(tuple_data_bytea, tuple_data_len + VARHDRSZ);
memcpy(VARDATA(tuple_data_bytea), (char *) tuphdr + tuphdr->t_hoff,
tuple_data_len); // < ------------------- USAGE
values[13] = PointerGetDatum(tuple_data_bytea);
/*
* We already checked that the item is completely within the raw
* page passed to us, with the length given in the line pointer.
* Let's check that t_hoff doesn't point over lp_len, before using
* it to access t_bits and oid.
*/
if (tuphdr->t_hoff >= SizeofHeapTupleHeader &&
tuphdr->t_hoff <= lp_len && // < ------------------ VERIFICATION
tuphdr->t_hoff == MAXALIGN(tuphdr->t_hoff))
{
--------
I hope, this problem can be fixed really easily.
Thanks&Regards,
Kovalenko Dmitry
PostgresPro, Russia.
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, d.kovalenko@postgrespro.ru
Subject: Re: BUG #18896: A potential problem in heap_page_items (pageinspect, PG-17)
In-Reply-To: <18896-add267b8e06663e3@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