]> 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>
Thu, 26 Dec 2024 11:45:31 +0000 (12:45 +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>
lib/fileeq.c

index 1f7f90ccb5c10015fb97c6812a210ff8259320d1..d0ba77cc3d7cdc1e9c771f08000913d55d5b4f7d 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));