summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorStefan Ott <stefan@ott.net>2020-04-04 01:34:33 +0200
committerSolomon Peachy <pizza@shaftnet.org>2020-04-07 00:20:13 +0200
commit63bf8e4acdbcbfc03e5023291c9ee137f858969f (patch)
tree87d67861b88fd6594b06bafac904ed1201c710fe /firmware
parent180cef835bf40d0081895773aaa637ac926bb0ac (diff)
downloadrockbox-63bf8e4acdbcbfc03e5023291c9ee137f858969f.tar.gz
rockbox-63bf8e4acdbcbfc03e5023291c9ee137f858969f.zip
Consider sector size when checking cluster size
On file systems with 2048 bytes per cluster, the bpb_secperclus value gets multiplied by 4 when the meta data is loaded. This patch changes the sanity check to consider (and reverse) that multiplication before checking the cluster size. Signed-off-by: Stefan Ott <stefan@ott.net>
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/fat.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index fed3baffd4..b14e461a65 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -391,7 +391,12 @@ static int bpb_is_sane(struct bpb *fat_bpb)
391 return -1; 391 return -1;
392 } 392 }
393 393
394 if (fat_bpb->bpb_secperclus * fat_bpb->bpb_bytspersec > 128*1024ul) 394 /* The fat_bpb struct does not hold the raw value of bpb_bytspersec, the
395 * value is multiplied in cases where bpb_bytspersec != SECTOR_SIZE. We need
396 * to undo that multiplication before we do the sanity check. */
397 unsigned long secmult = fat_bpb->bpb_bytspersec / SECTOR_SIZE;
398
399 if (fat_bpb->bpb_secperclus * fat_bpb->bpb_bytspersec / secmult > 128*1024ul)
395 { 400 {
396 DEBUGF("%s() - Error: cluster size is larger than 128K " 401 DEBUGF("%s() - Error: cluster size is larger than 128K "
397 "(%lu * %lu = %lu)\n", __func__, 402 "(%lu * %lu = %lu)\n", __func__,