From 55620c1d13fdb0421673a6b8a1892cabff6c011f Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 13 Mar 2021 19:55:19 +0300 Subject: [PATCH] mdbx: fix selecting/adjustment values inside `mdbx_env_set_geometry()` for implicit out-of-range cases. Fixes https://github.com/erthink/libmdbx/issues/170. Change-Id: Ibc8754811aa3d9077447220f9fec7a5543e40cc4 --- ChangeLog.md | 1 + src/core.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index afe05d4f..e12409f2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -35,6 +35,7 @@ Fixes: - Fixed "reincarnation" of subDB after it deletion (https://github.com/erthink/libmdbx/issues/168). - Fixed (disallowing) implicit subDB deletion via operations on `@MAIN`'s DBI-handle. - Fixed a crash of `mdbx_env_info_ex()` in case of a call for a non-open environment (https://github.com/erthink/libmdbx/issues/171). + - Fixed the selecting/adjustment values inside `mdbx_env_set_geometry()` for implicit out-of-range cases (https://github.com/erthink/libmdbx/issues/170). ## v0.9.3 at 2021-02-02 diff --git a/src/core.c b/src/core.c index 2a321525..a1439a8f 100644 --- a/src/core.c +++ b/src/core.c @@ -10594,8 +10594,11 @@ mdbx_env_set_geometry(MDBX_env *env, intptr_t size_lower, intptr_t size_now, if (MIN_MAPSIZE / pagesize < MIN_PAGENO) size_lower = MIN_PAGENO * pagesize; } - if (size_lower == INTPTR_MAX) + if (size_lower >= INTPTR_MAX) { size_lower = MAX_MAPSIZE; + if ((size_t)size_lower / pagesize > MAX_PAGENO) + size_lower = pagesize * MAX_PAGENO; + } if (size_now <= 0) { size_now = DEFAULT_MAPSIZE; @@ -10604,8 +10607,11 @@ mdbx_env_set_geometry(MDBX_env *env, intptr_t size_lower, intptr_t size_now, if (size_upper >= size_lower && size_now > size_upper) size_now = size_upper; } - if (size_now == INTPTR_MAX) + if (size_now >= INTPTR_MAX) { size_now = MAX_MAPSIZE; + if ((size_t)size_now / pagesize > MAX_PAGENO) + size_now = pagesize * MAX_PAGENO; + } if (size_upper <= 0) { if ((size_t)size_now >= MAX_MAPSIZE / 2) @@ -10621,6 +10627,10 @@ mdbx_env_set_geometry(MDBX_env *env, intptr_t size_lower, intptr_t size_now, } if ((size_t)size_upper / pagesize > MAX_PAGENO) size_upper = pagesize * MAX_PAGENO; + } else if (size_upper >= INTPTR_MAX) { + size_upper = MAX_MAPSIZE; + if ((size_t)size_upper / pagesize > MAX_PAGENO) + size_upper = pagesize * MAX_PAGENO; } if (unlikely(size_lower < (intptr_t)MIN_MAPSIZE || size_lower > size_upper)) {