diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-10 06:57:39 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-10 06:57:39 +0000 |
commit | 0a02ae47cf0e9acf08e912a0a0c62efe57544e14 (patch) | |
tree | 74b106e081ec97afca7cc2b7caa5992227b9c12b | |
parent | 19f92651d8b8391dd0727e0cd8aba3fd57eae079 (diff) | |
parent | 9558e6ac2e10ab0fef46fdd14187b840555f86f4 (diff) | |
download | fsck_msdos-android13-mainline-permission-release.tar.gz |
Snap for 8564071 from 9558e6ac2e10ab0fef46fdd14187b840555f86f4 to mainline-permission-releaseaml_per_341711000aml_per_341614000aml_per_341510010aml_per_341410020aml_per_341311000aml_per_341110020aml_per_341110010aml_per_341011100aml_per_341011020aml_per_340916010aml_per_331913010aml_per_331812030aml_per_331710050aml_per_331611010aml_per_331512020aml_per_331411000aml_per_331313010aml_per_331115020aml_per_331019040aml_per_330912010aml_per_330811030android14-mainline-permission-releaseandroid13-mainline-permission-release
Change-Id: Ic297320cf62a7faba5fc861f3b9d69c27b736322
-rw-r--r-- | dir.c | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -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; |