pgsql: amcheck: Fix verify_heapam for tuples where xmin or xmax is 0.

From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: amcheck: Fix verify_heapam for tuples where xmin or xmax is 0.
Date: 2023-03-24 15:13:52
Message-ID: E1pfj71-005AlA-RQ@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

amcheck: Fix verify_heapam for tuples where xmin or xmax is 0.

In such cases, get_xid_status() doesn't set its output parameter (the
third argument), so we shouldn't fall through to code which will test
the value of that parameter. There are five existing calls to
get_xid_status(), three of which seem to already handle this case
properly. This commit tries to fix the other two.

If we're checking xmin and find that it is invalid (i.e. 0) just
report that as corruption, similar to what's already done in the
three cases that seem correct. If we're checking xmax and find
that's invalid, that's fine: it just means that the tuple hasn't
been updated or deleted.

Thanks to Andres Freund and valgrind for finding this problem, and
also to Andres for having a look at the patch. This bug seems to go
all the way back to where verify_heapam was first introduced, but
wasn't detected until recently, possibly because of the new test cases
added for update chain verification. Back-patch to v14, where this
code showed up.

Discussion: http://postgr.es/m/CA+TgmoZAYzQZqyUparXy_ks3OEOfLD9-bEXt8N-2tS1qghX9gQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e88754a1965c0f40a723e6e46d670cacda9e19bd

Modified Files
--------------
contrib/amcheck/verify_heapam.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Jeff Davis 2023-03-24 16:10:27 pgsql: Avoid potential UCollator leak for older ICU versions.
Previous Message Andrew Dunstan 2023-03-24 13:21:40 Re: pgsql: meson: add install-{quiet, world} targets

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2023-03-24 15:47:20 Re: User functions for building SCRAM secrets
Previous Message Peter Eisentraut 2023-03-24 15:07:42 Re: Make ON_ERROR_STOP stop on shell script failure