Commit 550868a
f2fs-tools: fix division-by-zero exception during formatting of undersized devices
When formatting a device that is too small , the error handling in
f2fs_prepare_super_block() is flawed, leading to a division-by-zero
exception.
Reproducer:
root@vm:~/f2fs-tools# dd if=/dev/zero of=data.6M bs=1M count=6
root@vm:~/f2fs-tools# losetup -f data.6M
root@vm:~/f2fs-tools# mkfs.f2fs /dev/loop0
This patch adds a check to verify if the device has enough capacity to
store the metadata area. If not, it immediately returns an error to
prevent the subsequent division-by-zero exception from being triggered.
Signed-off-by: Yongpeng Yang <yangyongpeng@xiaomi.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>1 parent c4933c2 commit 550868a
1 file changed
Lines changed: 23 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| 271 | + | |
271 | 272 | | |
272 | 273 | | |
273 | 274 | | |
| |||
426 | 427 | | |
427 | 428 | | |
428 | 429 | | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
429 | 436 | | |
430 | | - | |
431 | | - | |
| 437 | + | |
432 | 438 | | |
433 | 439 | | |
434 | 440 | | |
| |||
494 | 500 | | |
495 | 501 | | |
496 | 502 | | |
497 | | - | |
498 | | - | |
| 503 | + | |
499 | 504 | | |
500 | | - | |
501 | | - | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
502 | 513 | | |
503 | 514 | | |
504 | 515 | | |
| |||
563 | 574 | | |
564 | 575 | | |
565 | 576 | | |
566 | | - | |
567 | | - | |
568 | | - | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
569 | 581 | | |
| 582 | + | |
| 583 | + | |
570 | 584 | | |
571 | 585 | | |
572 | 586 | | |
| |||
0 commit comments