From 70c1ffbdf4ecac30536e1af13764adbd883a161d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 26 Dec 2024 12:45:31 +0100 Subject: [PATCH] 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 --- lib/fileeq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fileeq.c b/lib/fileeq.c index 1f7f90ccb5c..d0ba77cc3d7 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));