:: commit ec8da75b2f5e074678694231cdea7c256793bff2

Mintsuki <mintsuki@protonmail.com> — 2026-01-12 22:47

parents: 66499e9024

fat32: Fix integer overflow in cluster count calculation

diff --git a/common/fs/fat32.s2.c b/common/fs/fat32.s2.c
index 60c24ed9..17bf649b 100644
--- a/common/fs/fat32.s2.c
+++ b/common/fs/fat32.s2.c
@@ -679,7 +679,7 @@ struct file_handle *fat32_open(struct volume *part, const char *path) {
             ret->first_cluster = current_file.cluster_num_low;
             if (context.type == 32)
                 ret->first_cluster |= (uint64_t)current_file.cluster_num_high << 16;
-            ret->size_clusters = DIV_ROUNDUP(current_file.file_size_bytes, context.bytes_per_sector);
+            ret->size_clusters = DIV_ROUNDUP((uint64_t)current_file.file_size_bytes, context.bytes_per_sector);
             ret->size_bytes = current_file.file_size_bytes;
             // Initialize chain_len before calling cache_cluster_chain
             // (cache_cluster_chain may return NULL without setting it for empty files)
tab: 248 wrap: offon