Skip to content

Commit

Permalink
hardlink: fix memory corruption (size calculation)
Browse files Browse the repository at this point in the history
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: util-linux#3330
Signed-off-by: Karel Zak <kzak@redhat.com>
  • Loading branch information
karelzak committed Dec 26, 2024
1 parent 4e14b57 commit 70c1ffb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/fileeq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 70c1ffb

Please sign in to comment.