Page MenuHomeFreeBSD

Fix an integer overflow on 32-bit platforms.
ClosedPublic

Authored by delphij on Sep 22 2020, 9:30 PM.

Details

Summary

sbin/fsck_msdosfs: Fix an integer overflow on 32-bit platforms.

The purpose of checksize() is to verify that the referenced cluster chain
size matches the recorded file size (up to 2^32 - 1) in the directory
entry. We follow the cluster chain, then multiple the cluster count by
bytes per cluster to get the physical size, and then examine it against
the recorded size.

When a file is close to 4 GiB (between 4GiB - cluster size and 4GiB, both
non-inclusive), the product of cluster count and bytes per cluster would
be exactly 4 GiB. On 32-bit systems, because size_t is 32-bit, this would
wrap back to 0, which will cause the file be truncated to 0.

Fix this by using 64-bit physicalSize instead.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.