mdbx: return MDBX_CORRUPTED instead of MDBX_PAGE_NOTFOUND for invalid pages.

This commit is contained in:
Leonid Yuriev 2021-10-15 01:11:20 +03:00
parent 7251f47d5b
commit 514910621e

View File

@ -13116,10 +13116,11 @@ mdbx_page_get_ex(MDBX_cursor *const mc, const pgno_t pgno,
mdbx_tassert(txn, front <= txn->mt_front); mdbx_tassert(txn, front <= txn->mt_front);
if (unlikely(pgno >= txn->mt_next_pgno)) { if (unlikely(pgno >= txn->mt_next_pgno)) {
mdbx_error("page #%" PRIaPGNO " beyond next-pgno", pgno); mdbx_error("page #%" PRIaPGNO " beyond next-pgno", pgno);
notfound:
ret.page = nullptr; ret.page = nullptr;
corrupted:
mc->mc_txn->mt_flags |= MDBX_TXN_ERROR;
ret.err = MDBX_PAGE_NOTFOUND; ret.err = MDBX_PAGE_NOTFOUND;
bailout:
mc->mc_txn->mt_flags |= MDBX_TXN_ERROR;
return ret; return ret;
} }
@ -13159,33 +13160,36 @@ dirty:
"mismatch actual pgno (%" PRIaPGNO ") != expected (%" PRIaPGNO "mismatch actual pgno (%" PRIaPGNO ") != expected (%" PRIaPGNO
")\n", ")\n",
ret.page->mp_pgno, pgno); ret.page->mp_pgno, pgno);
goto corrupted; goto notfound;
} }
#if !MDBX_DISABLE_PAGECHECKS #if !MDBX_DISABLE_PAGECHECKS
if (unlikely(ret.page->mp_flags & P_ILL_BITS)) { if (unlikely(ret.page->mp_flags & P_ILL_BITS)) {
bad_page(ret.page, "invalid page's flags (%u)\n", ret.page->mp_flags); ret.err =
goto corrupted; bad_page(ret.page, "invalid page's flags (%u)\n", ret.page->mp_flags);
goto bailout;
} }
if (unlikely(ret.page->mp_txnid > front) && if (unlikely(ret.page->mp_txnid > front) &&
unlikely(ret.page->mp_txnid > txn->mt_front || front < txn->mt_txnid)) { unlikely(ret.page->mp_txnid > txn->mt_front || front < txn->mt_txnid)) {
bad_page(ret.page, ret.err = bad_page(
"invalid page txnid (%" PRIaTXN ") for %s' txnid (%" PRIaTXN ")\n", ret.page,
ret.page->mp_txnid, "invalid page txnid (%" PRIaTXN ") for %s' txnid (%" PRIaTXN ")\n",
(front == txn->mt_front && front != txn->mt_txnid) ? "front-txn" ret.page->mp_txnid,
: "parent-page", (front == txn->mt_front && front != txn->mt_txnid) ? "front-txn"
front); : "parent-page",
goto corrupted; front);
goto bailout;
} }
if (unlikely((ret.page->mp_upper < ret.page->mp_lower || if (unlikely((ret.page->mp_upper < ret.page->mp_lower ||
((ret.page->mp_lower | ret.page->mp_upper) & 1) || ((ret.page->mp_lower | ret.page->mp_upper) & 1) ||
PAGEHDRSZ + ret.page->mp_upper > env->me_psize) && PAGEHDRSZ + ret.page->mp_upper > env->me_psize) &&
!IS_OVERFLOW(ret.page))) { !IS_OVERFLOW(ret.page))) {
bad_page(ret.page, "invalid page lower(%u)/upper(%u) with limit (%u)\n", ret.err =
ret.page->mp_lower, ret.page->mp_upper, page_space(env)); bad_page(ret.page, "invalid page lower(%u)/upper(%u) with limit (%u)\n",
goto corrupted; ret.page->mp_lower, ret.page->mp_upper, page_space(env));
goto bailout;
} }
#endif /* !MDBX_DISABLE_PAGECHECKS */ #endif /* !MDBX_DISABLE_PAGECHECKS */