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