Skip to content

Commit 8fd5aa7

Browse files
committed
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
1 parent 9dac02c commit 8fd5aa7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

contrib/amcheck/verify_heapam.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ check_tuple_visibility(HeapCheckContext *ctx)
774774
switch (get_xid_status(xmin, ctx, &xmin_status))
775775
{
776776
case XID_INVALID:
777+
report_corruption(ctx,
778+
pstrdup("xmin is invalid"));
779+
return false;
777780
case XID_BOUNDS_OK:
778781
break;
779782
case XID_IN_FUTURE:
@@ -1109,6 +1112,9 @@ check_tuple_visibility(HeapCheckContext *ctx)
11091112
xmax = HeapTupleHeaderGetRawXmax(tuphdr);
11101113
switch (get_xid_status(xmax, ctx, &xmax_status))
11111114
{
1115+
case XID_INVALID:
1116+
ctx->tuple_could_be_pruned = false;
1117+
return true;
11121118
case XID_IN_FUTURE:
11131119
report_corruption(ctx,
11141120
psprintf("xmax %u equals or exceeds next valid transaction ID %u:%u",
@@ -1131,7 +1137,6 @@ check_tuple_visibility(HeapCheckContext *ctx)
11311137
XidFromFullTransactionId(ctx->oldest_fxid)));
11321138
return false; /* corrupt */
11331139
case XID_BOUNDS_OK:
1134-
case XID_INVALID:
11351140
break;
11361141
}
11371142

0 commit comments

Comments
 (0)