Whamcloud - gitweb
e2fsck: fix potential fencepost error in e2fsck_should_rebuild_extents()
authorTheodore Ts'o <tytso@mit.edu>
Tue, 9 Aug 2022 14:52:57 +0000 (10:52 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 9 Aug 2022 14:52:57 +0000 (10:52 -0400)
commit7464397a0c5df0416a7ef3436747045b36fb7882
tree7d81729fea2b00e05c6877936addf6b90054dec2
parentb770b0fe7e2564afd95f2008533c6db435e74456
e2fsck: fix potential fencepost error in e2fsck_should_rebuild_extents()

The ext2_extent_info.max_depth is zero-based (e.g., it is zero when
the entire extent tree fits in the inode).  Hence, if it is equal to
MAX_EXTENT_DEPTH_COUNT we should always rebuild the extent tree to
shorten it.

Also, for 1k block file systems, it's possible for the worst-case
extent tree in its most compact form to have a maximum depth of 6, not
5.  So set MAX_EXTENT_DEPTH_COUNT to 8 just to be sure we have plenty
of headroom.  (The kernel supports an extent depth up to 2**16, but
e2fsck only keeps statistics up to MAX_EXTENT_DEPTH_COUNT, and if it's
deeper than that, we know that it will be profitable to rebuild the
extent tree in any case.)

Addresses-Coverity-Bug: 1507761
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/e2fsck.h
e2fsck/extents.c