mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-30 11:29:19 +08:00
mdbx: fix MDBX_CORRUPTED due open/shrink collision.
This commit is contained in:
parent
a150b791a4
commit
22e7630d53
25
src/mdbx.c
25
src/mdbx.c
@ -4742,6 +4742,11 @@ static int __cold mdbx_read_header(MDBX_env *env, MDBX_meta *meta,
|
||||
return MDBX_INVALID;
|
||||
}
|
||||
|
||||
if (!retryleft) {
|
||||
mdbx_error("meta[%u] is too volatile, skip it", meta_number);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* LY: check pagesize */
|
||||
if (!mdbx_is_power2(page.mp_meta.mm_psize) ||
|
||||
page.mp_meta.mm_psize < MIN_PAGESIZE ||
|
||||
@ -4759,11 +4764,6 @@ static int __cold mdbx_read_header(MDBX_env *env, MDBX_meta *meta,
|
||||
page.mp_meta.mm_psize);
|
||||
}
|
||||
|
||||
if (!retryleft) {
|
||||
mdbx_error("meta[%u] is too volatile, skip it", meta_number);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (page.mp_meta.mm_txnid_a != page.mp_meta.mm_txnid_b) {
|
||||
mdbx_warning("meta[%u] not completely updated, skip it", meta_number);
|
||||
continue;
|
||||
@ -4830,11 +4830,16 @@ static int __cold mdbx_read_header(MDBX_env *env, MDBX_meta *meta,
|
||||
const uint64_t used_bytes =
|
||||
page.mp_meta.mm_geo.next * (uint64_t)page.mp_meta.mm_psize;
|
||||
if (used_bytes > *filesize) {
|
||||
mdbx_notice("meta[%u] used-bytes (%" PRIu64 ") beyond filesize (%" PRIu64
|
||||
"), skip it",
|
||||
meta_number, used_bytes, *filesize);
|
||||
rc = MDBX_CORRUPTED;
|
||||
continue;
|
||||
rc = mdbx_filesize(env->me_fd, filesize);
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
return rc;
|
||||
if (used_bytes > *filesize) {
|
||||
mdbx_notice("meta[%u] used-bytes (%" PRIu64
|
||||
") beyond filesize (%" PRIu64 "), skip it",
|
||||
meta_number, used_bytes, *filesize);
|
||||
rc = MDBX_CORRUPTED;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* LY: check mapsize limits */
|
||||
|
Loading…
Reference in New Issue
Block a user