If the extent tree has out-of-range physical block numbers, don't try
to release them.
Also add a similar check in ext2fs_block_alloc_stats2() to avoid a
NULL pointer dereference.
Reported-by: Nils Bars <nils.bars@rub.de>
Reported-by: Moritz Schlögel <moritz.schloegel@rub.de>
Reported-by: Nico Schiller <nico.schiller@rub.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
{
int group = ext2fs_group_of_blk2(fs, blk);
- if (blk >= ext2fs_blocks_count(fs->super)) {
+ if (blk < fs->super->s_first_data_block ||
+ blk >= ext2fs_blocks_count(fs->super)) {
#ifndef OMIT_COM_ERR
com_err("ext2fs_block_alloc_stats", 0,
"Illegal block number: %lu", (unsigned long) blk);
__u32 cluster_freed;
errcode_t retval = 0;
+ if (free_start < fs->super->s_first_data_block ||
+ (free_start + free_count) >= ext2fs_blocks_count(fs->super))
+ return EXT2_ET_BAD_BLOCK_NUM;
+
/* No bigalloc? Just free each block. */
if (EXT2FS_CLUSTER_RATIO(fs) == 1) {
*freed += free_count;