From: Eric Biggers <ebigg...@google.com>

Cleanly report an error instead of dividing by 0 (causing a floating
point exception) in the following case:

        truncate -s 16M img && mkfs.f2fs img

Note that this is a minimal fix; it appears that overly-small images
still cause various integer overflows in f2fs_prepare_super_block().

Signed-off-by: Eric Biggers <ebigg...@google.com>
---
 mkfs/f2fs_format.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 7cd5815..40ac589 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -467,7 +467,8 @@ static int f2fs_prepare_super_block(void)
 
        total_zones = get_sb(segment_count) / (c.segs_per_zone) -
                                                        total_meta_zones;
-
+       if (total_zones == 0)
+               goto too_small;
        set_sb(section_count, total_zones * c.secs_per_zone);
 
        set_sb(segment_count_main, get_sb(section_count) * c.segs_per_sec);
@@ -497,8 +498,7 @@ static int f2fs_prepare_super_block(void)
                        c.sector_size < zone_align_start_offset) ||
                (get_sb(segment_count_main) - NR_CURSEG_TYPE) <
                                                c.reserved_segments) {
-               MSG(0, "\tError: Device size is not sufficient for F2FS 
volume\n");
-               return -1;
+               goto too_small;
        }
 
        if (c.vol_uuid) {
@@ -612,6 +612,10 @@ static int f2fs_prepare_super_block(void)
        }
 
        return 0;
+
+too_small:
+       MSG(0, "\tError: Device size is not sufficient for F2FS volume\n");
+       return -1;
 }
 
 static int f2fs_init_sit_area(void)

base-commit: 6148db344eb25b23a7cbde36d026011cd15b6143
-- 
2.37.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to