summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2020-09-23 16:14:23 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-09-23 16:14:23 +0000
commitc6bf77e339aae8ed16d124dbb292783448c4c9fd (patch)
tree2f42e0a6005555f8268146a70e056467dafea60c
parent063c1723a6c2c0259fde18efa969cbbd62dcc73b (diff)
parenta1c9005dc8405d858cef28d8d563c57e3c9aefc6 (diff)
downloadfsck_msdos-c6bf77e339aae8ed16d124dbb292783448c4c9fd.tar.gz
Merge "Sync with upstream 667eef4ac (svn revision 366064 + 366065)." am: b86e97b62c am: a1c9005dc8
Original change: https://android-review.googlesource.com/c/platform/external/fsck_msdos/+/1434752 Change-Id: Ib6032533fcbc77dd2b14134bcae4499e6148f2df
-rw-r--r--dir.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/dir.c b/dir.c
index 6bdc3b4..010bd65 100644
--- a/dir.c
+++ b/dir.c
@@ -388,7 +388,8 @@ static int
checksize(struct fat_descriptor *fat, u_char *p, struct dosDirEntry *dir)
{
int ret = FSOK;
- size_t physicalSize;
+ size_t chainsize;
+ u_int64_t physicalSize;
struct bootblock *boot;
boot = fat_get_boot(fat);
@@ -401,9 +402,9 @@ checksize(struct fat_descriptor *fat, u_char *p, struct dosDirEntry *dir)
} else {
if (!fat_is_valid_cl(fat, dir->head))
return FSERROR;
- ret = checkchain(fat, dir->head, &physicalSize);
+ ret = checkchain(fat, dir->head, &chainsize);
/*
- * Upon return, physicalSize would hold the chain length
+ * Upon return, chainsize would hold the chain length
* that checkchain() was able to validate, but if the user
* refused the proposed repair, it would be unsafe to
* proceed with directory entry fix, so bail out in that
@@ -412,10 +413,16 @@ checksize(struct fat_descriptor *fat, u_char *p, struct dosDirEntry *dir)
if (ret == FSERROR) {
return (FSERROR);
}
- physicalSize *= boot->ClusterSize;
+ /*
+ * The maximum file size on FAT32 is 4GiB - 1, which
+ * will occupy a cluster chain of exactly 4GiB in
+ * size. On 32-bit platforms, since size_t is 32-bit,
+ * it would wrap back to 0.
+ */
+ physicalSize = (u_int64_t)chainsize * boot->ClusterSize;
}
if (physicalSize < dir->size) {
- pwarn("size of %s is %u, should at most be %zu\n",
+ pwarn("size of %s is %u, should at most be %" PRIu64 "\n",
fullpath(dir), dir->size, physicalSize);
if (ask(1, "Truncate")) {
dir->size = physicalSize;