]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hardlink: fix memory corruption (size calculation)
authorKarel Zak <kzak@redhat.com>
Thu, 26 Dec 2024 11:45:31 +0000 (12:45 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 3 Jan 2025 11:21:43 +0000 (12:21 +0100)
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 <kzak@redhat.com>
(cherry picked from commit 70c1ffbdf4ecac30536e1af13764adbd883a161d)

lib/fileeq.c

index 2a74af8a79932c5537272ec98c4b825cf451b34e..2d5038c4e4b00ab1d07fa2909f2bcbd977aa7477 100644 (file)
@@ -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));