Skip to content

Commit e88754a

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 a04761a commit e88754a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

contrib/amcheck/verify_heapam.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,9 @@ check_tuple_visibility(HeapCheckContext *ctx, bool *xmin_commit_status_ok,
10121012
switch (get_xid_status(xmin, ctx, &xmin_status))
10131013
{
10141014
case XID_INVALID:
1015-
break;
1015+
report_corruption(ctx,
1016+
pstrdup("xmin is invalid"));
1017+
return false;
10161018
case XID_BOUNDS_OK:
10171019
*xmin_commit_status_ok = true;
10181020
*xmin_commit_status = xmin_status;
@@ -1350,6 +1352,9 @@ check_tuple_visibility(HeapCheckContext *ctx, bool *xmin_commit_status_ok,
13501352
xmax = HeapTupleHeaderGetRawXmax(tuphdr);
13511353
switch (get_xid_status(xmax, ctx, &xmax_status))
13521354
{
1355+
case XID_INVALID:
1356+
ctx->tuple_could_be_pruned = false;
1357+
return true;
13531358
case XID_IN_FUTURE:
13541359
report_corruption(ctx,
13551360
psprintf("xmax %u equals or exceeds next valid transaction ID %u:%u",
@@ -1372,7 +1377,6 @@ check_tuple_visibility(HeapCheckContext *ctx, bool *xmin_commit_status_ok,
13721377
XidFromFullTransactionId(ctx->oldest_fxid)));
13731378
return false; /* corrupt */
13741379
case XID_BOUNDS_OK:
1375-
case XID_INVALID:
13761380
break;
13771381
}
13781382

0 commit comments

Comments
 (0)