If the number of blocks or inodes per block group is not a multiple of
8 (which are invalid values) ext2fs_image_bitmap{read,write} can loop
forever. These file systems should be not be allowed to be opened
(without EXT2_FLAG_IGNORE_SB_ERRORS) but for the fact that a long time
ago, Android devices used a buggy (but BSD-licensed, which was what
was important to the early Android founders) program for creating file
systems which would create these invalid file systems. E2fsck
couldn't actually correctly repair these file systems, but adding a
check to enforce this (in e2fsprogs and in the kernel) would have
broken some of these devices, so support for these bogus file system
was in a grey area for many years.
We will be tightening this up soon, but for now, we'll apply this
quick fix so attempts to use e2image won't hang forever. (Not that
Android ever shipped e2image in those days, of course...)
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
size = sizeof(buf);
if (size > (cnt >> 3))
size = (cnt >> 3);
+ if (size == 0)
+ break;
retval = ext2fs_get_generic_bmap_range(bmap, itr,
size << 3, buf);
size = sizeof(buf);
if (size > (cnt >> 3))
size = (cnt >> 3);
+ if (size == 0)
+ break;
actual = read(fd, buf, size);
if (actual == -1)