From: Karel Zak Date: Thu, 26 Dec 2024 11:45:31 +0000 (+0100) Subject: hardlink: fix memory corruption (size calculation) X-Git-Tag: v2.42-start~107^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=70c1ffbdf4ecac30536e1af13764adbd883a161d;p=thirdparty%2Futil-linux.git hardlink: fix memory corruption (size calculation) The current code rounds down the values for readsiz and blocksmax, which is incorrect. The sizes must be large enough to match the files. Addresses: https://github.com/util-linux/util-linux/issues/3330 Signed-off-by: Karel Zak --- diff --git a/lib/fileeq.c b/lib/fileeq.c index 1f7f90ccb..d0ba77cc3 100644 --- a/lib/fileeq.c +++ b/lib/fileeq.c @@ -272,12 +272,12 @@ size_t ul_fileeq_set_size(struct ul_fileeq *eq, uint64_t filesiz, nreads = filesiz / readsiz; /* enlarge readsize for large files */ if (nreads > maxdigs) - readsiz = filesiz / maxdigs; + readsiz = (filesiz + maxdigs - 1) / maxdigs; break; } eq->readsiz = readsiz; - eq->blocksmax = filesiz / readsiz; + eq->blocksmax = (filesiz + readsiz - 1) / readsiz; DBG(EQ, ul_debugobj(eq, "set sizes: filesiz=%ju, maxblocks=%" PRIu64 ", readsiz=%zu", eq->filesiz, eq->blocksmax, eq->readsiz));