From c27787eb316b97004b898a94ff752f3584324ef7 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: Sun, 13 Feb 2022 17:04:10 +0300 Subject: [PATCH] mdbx: fix potential `SIGSEGV` for DB with non-default page size. Related to https://github.com/erthink/libmdbx/issues/267. --- src/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core.c b/src/core.c index 3d5a6064..9a397cc6 100644 --- a/src/core.c +++ b/src/core.c @@ -11114,6 +11114,10 @@ __cold static void mdbx_setup_pagesize(MDBX_env *env, const size_t pagesize) { mdbx_ensure(env, pagesize >= MIN_PAGESIZE); mdbx_ensure(env, pagesize <= MAX_PAGESIZE); env->me_psize = (unsigned)pagesize; + if (env->me_pbuf) { + mdbx_memalign_free(env->me_pbuf); + env->me_pbuf = nullptr; + } STATIC_ASSERT(MAX_GC1OVPAGE(MIN_PAGESIZE) > 4); STATIC_ASSERT(MAX_GC1OVPAGE(MAX_PAGESIZE) < MDBX_PGL_LIMIT); @@ -11722,7 +11726,8 @@ __cold static int mdbx_setup_dxb(MDBX_env *env, const int lck_rc, pv2pages(meta.mm_geo.grow_pv), pv2pages(meta.mm_geo.shrink_pv), unaligned_peek_u64(4, meta.mm_txnid_a), mdbx_durable_str(&meta)); - mdbx_setup_pagesize(env, meta.mm_psize); + if (env->me_psize != meta.mm_psize) + mdbx_setup_pagesize(env, meta.mm_psize); const size_t used_bytes = pgno2bytes(env, meta.mm_geo.next); const size_t used_aligned2os_bytes = ceil_powerof2(used_bytes, env->me_os_psize);