]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
sbin/fsck_msdosfs: Fix an integer overflow on 32-bit platforms.
authorXin LI <delphij@FreeBSD.org>
Wed, 23 Sep 2020 06:52:22 +0000 (06:52 +0000)
committerXin LI <delphij@FreeBSD.org>
Wed, 23 Sep 2020 06:52:22 +0000 (06:52 +0000)
commit4d2c300bdeb3d4a8b62ac269c06c1b5cd89f604c
tree13b28aa809c6df4baf2c34121eb6eafbb8628e28
parentd20d17f6d4b023acff418314805e21839246da09
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, then
check 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.

This fix is inspired by an Android change request at
https://android-review.googlesource.com/c/platform/external/fsck_msdos/+/1428461

PR: 249533
Reviewed by: kevlo
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D26524
sbin/fsck_msdosfs/dir.c