summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-11-11 02:14:07 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-11-11 02:14:07 +0000
commit95cb374a726c0d1288f822aa8b25d62716aa26a6 (patch)
tree74b106e081ec97afca7cc2b7caa5992227b9c12b
parent355a40090c27dab22afbaa50387c3784328a1147 (diff)
parent3ebf4e2414b41e76228004fa6619ea04a9a38b6a (diff)
downloadfsck_msdos-95cb374a726c0d1288f822aa8b25d62716aa26a6.tar.gz
Merge "Snap for 7904124 from 023cbbf051365f67883f82a9eaa759e1bcbfd814 to sdk-release" into sdk-release
-rw-r--r--dir.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/dir.c b/dir.c
index 010bd65..dbe4e0c 100644
--- a/dir.c
+++ b/dir.c
@@ -400,8 +400,21 @@ checksize(struct fat_descriptor *fat, u_char *p, struct dosDirEntry *dir)
if (dir->head == CLUST_FREE) {
physicalSize = 0;
} else {
- if (!fat_is_valid_cl(fat, dir->head))
- return FSERROR;
+ if (!fat_is_valid_cl(fat, dir->head) || !fat_is_cl_head(fat, dir->head)) {
+ pwarn("Directory entry %s of size %u referencing invalid cluster %u\n",
+ fullpath(dir), dir->size, dir->head);
+ if (ask(1, "Truncate")) {
+ p[28] = p[29] = p[30] = p[31] = 0;
+ p[26] = p[27] = 0;
+ if (boot->ClustMask == CLUST32_MASK)
+ p[20] = p[21] = 0;
+ dir->size = 0;
+ dir->head = CLUST_FREE;
+ return FSDIRMOD;
+ } else {
+ return FSERROR;
+ }
+ }
ret = checkchain(fat, dir->head, &chainsize);
/*
* Upon return, chainsize would hold the chain length
@@ -422,8 +435,8 @@ checksize(struct fat_descriptor *fat, u_char *p, struct dosDirEntry *dir)
physicalSize = (u_int64_t)chainsize * boot->ClusterSize;
}
if (physicalSize < dir->size) {
- pwarn("size of %s is %u, should at most be %" PRIu64 "\n",
- fullpath(dir), dir->size, physicalSize);
+ pwarn("size of %s is %u, should at most be %ju\n",
+ fullpath(dir), dir->size, (uintmax_t)physicalSize);
if (ask(1, "Truncate")) {
dir->size = physicalSize;
p[28] = (u_char)physicalSize;