From ed93785d2c724fef2b4d5c43bbbe926455857367 Mon Sep 17 00:00:00 2001 From: Mark Dilger Date: Mon, 15 Mar 2021 17:26:47 -0700 Subject: [PATCH v7 4/4] Add extra check of toast pointer in amcheck When toast pointers are being verified in verify_heapam, add a check that the va_toastrelid field matches the oid of the toast table. --- contrib/amcheck/verify_heapam.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c index e614c12a14..5ccae46375 100644 --- a/contrib/amcheck/verify_heapam.c +++ b/contrib/amcheck/verify_heapam.c @@ -1069,6 +1069,15 @@ check_tuple_attribute(HeapCheckContext *ctx) */ VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr); + if (toast_pointer.va_toastrelid != ctx->rel->rd_rel->reltoastrelid) + { + report_corruption(ctx, + psprintf("attribute %u points to relation with oid %u not the toast relation with oid %u", + ctx->attnum, toast_pointer.va_toastrelid, + ctx->rel->rd_rel->reltoastrelid)); + return true; + } + ctx->attrsize = toast_pointer.va_extsize; ctx->endchunk = (ctx->attrsize - 1) / TOAST_MAX_CHUNK_SIZE; ctx->totalchunks = ctx->endchunk + 1; -- 2.21.1 (Apple Git-122.3)