From 4adc7aa58da8c82516b392412a457f4b8a6f3713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Sat, 12 Feb 2022 01:26:17 +0300 Subject: [PATCH] mdbx: add few checks to `mdbx_validate_meta()`. --- src/core.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core.c b/src/core.c index cdd88e56..ac50d64e 100644 --- a/src/core.c +++ b/src/core.c @@ -10542,12 +10542,12 @@ static int mdbx_validate_meta(MDBX_env *env, MDBX_meta *const meta, meta->mm_dbs[FREE_DBI].md_entries || meta->mm_dbs[FREE_DBI].md_leaf_pages || meta->mm_dbs[FREE_DBI].md_overflow_pages)) { - mdbx_warning("meta[%u] has false-empty GC, skip it", meta_number); + mdbx_warning("meta[%u] has false-empty %s, skip it", meta_number, "GC"); return MDBX_CORRUPTED; } } else if (unlikely(meta->mm_dbs[FREE_DBI].md_root >= meta->mm_geo.next)) { - mdbx_warning("meta[%u] has invalid GC-root %" PRIaPGNO ", skip it", - meta_number, meta->mm_dbs[FREE_DBI].md_root); + mdbx_warning("meta[%u] has invalid %s-root %" PRIaPGNO ", skip it", + meta_number, "GC", meta->mm_dbs[FREE_DBI].md_root); return MDBX_CORRUPTED; } @@ -10558,12 +10558,24 @@ static int mdbx_validate_meta(MDBX_env *env, MDBX_meta *const meta, meta->mm_dbs[MAIN_DBI].md_entries || meta->mm_dbs[MAIN_DBI].md_leaf_pages || meta->mm_dbs[MAIN_DBI].md_overflow_pages)) { - mdbx_warning("meta[%u] has false-empty maindb", meta_number); + mdbx_warning("meta[%u] has false-empty %s", meta_number, "MainDB"); return MDBX_CORRUPTED; } } else if (unlikely(meta->mm_dbs[MAIN_DBI].md_root >= meta->mm_geo.next)) { - mdbx_warning("meta[%u] has invalid maindb-root %" PRIaPGNO ", skip it", - meta_number, meta->mm_dbs[MAIN_DBI].md_root); + mdbx_warning("meta[%u] has invalid %s-root %" PRIaPGNO ", skip it", + meta_number, "MainDB", meta->mm_dbs[MAIN_DBI].md_root); + return MDBX_CORRUPTED; + } + + if (unlikely(meta->mm_dbs[FREE_DBI].md_mod_txnid > txnid)) { + mdbx_warning("meta[%u] has wrong md_mod_txnid %" PRIaTXN " for %s, skip it", + meta_number, meta->mm_dbs[FREE_DBI].md_mod_txnid, "GC"); + return MDBX_CORRUPTED; + } + + if (unlikely(meta->mm_dbs[MAIN_DBI].md_mod_txnid > txnid)) { + mdbx_warning("meta[%u] has wrong md_mod_txnid %" PRIaTXN " for %s, skip it", + meta_number, meta->mm_dbs[MAIN_DBI].md_mod_txnid, "MainDB"); return MDBX_CORRUPTED; }