ext2: check some more values for ext2_super_block

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

Fixes #13401.
This commit is contained in:
wangxingdsb 2017-03-28 08:34:54 -07:00 committed by Adrien Destugues
parent 2ff144d005
commit c8a27537a7
2 changed files with 15 additions and 2 deletions

View File

@ -202,9 +202,21 @@ DeviceOpener::GetSize(off_t* _size, uint32* _blockSize)
bool bool
ext2_super_block::IsValid() ext2_super_block::IsValid()
{ {
// TODO: check some more values! if (Magic() != (uint32)EXT2_SUPER_BLOCK_MAGIC
if (Magic() != (uint32)EXT2_SUPER_BLOCK_MAGIC) || BlockShift() > 16
|| BlocksPerGroup() != (1UL << BlockShift()) * 8
|| InodeSize() > (1UL << BlockShift())
|| RevisionLevel() > EXT2_MAX_REVISION
|| ReservedGDTBlocks() > (1UL << BlockShift()) / 4)
return false; return false;
if (Has64bitFeature()) {
if (GroupDescriptorSize() > EXT2_BLOCK_GROUP_64BIT_SIZE || GroupDescriptorSize() < EXT2_BLOCK_GROUP_NORMAL_SIZE)
return false;
}
else {
if (GroupDescriptorSize() != EXT2_BLOCK_GROUP_NORMAL_SIZE)
return false;
}
return true; return true;
} }

View File

@ -194,6 +194,7 @@ struct ext2_super_block {
#define EXT2_STATE_INVALID 0x02 #define EXT2_STATE_INVALID 0x02
#define EXT2_BLOCK_GROUP_NORMAL_SIZE 32 #define EXT2_BLOCK_GROUP_NORMAL_SIZE 32
#define EXT2_BLOCK_GROUP_64BIT_SIZE 64
// block group flags // block group flags
#define EXT2_BLOCK_GROUP_INODE_UNINIT 0x1 #define EXT2_BLOCK_GROUP_INODE_UNINIT 0x1