pub fn validate(&self, meta_size: u64) -> Result<()> {
        if !self.is_rafs_v5() {
            return Err(einval!("invalid super block version number"));
        } else if self.sb_size() as usize != RAFSV5_SUPERBLOCK_SIZE
            || meta_size <= RAFSV5_SUPERBLOCK_SIZE as u64
        {
            return Err(einval!("invalid super block blob size"));
        } else if !self.block_size().is_power_of_two()
            || self.block_size() < 0x1000
            || (self.block_size() as u64 > RAFS_MAX_CHUNK_SIZE && self.block_size() != 4 << 20)
        {
            // Stargz has a special chunk size of 4MB.
            return Err(einval!("invalid block size"));
        } else if RafsSuperFlags::from_bits(self.flags()).is_none() {
            return Err(einval!("invalid super block flags"));
        }

        let meta_range = MetaRange::new(
            RAFSV5_SUPERBLOCK_SIZE as u64,
            meta_size - RAFSV5_SUPERBLOCK_SIZE as u64,
            true,
        )?;

        let inodes_count = self.inodes_count();
        let inode_table_offset = self.inode_table_offset();
        let inode_table_entries = self.inode_table_entries() as u64;
        let inode_table_size = inode_table_entries * size_of::<u32>() as u64;
        let inode_table_range = MetaRange::new(inode_table_offset, inode_table_size, false)?;
        if inodes_count > inode_table_entries || !inode_table_range.is_subrange_of(&meta_range) {
            return Err(einval!("invalid inode table count, offset or entries."));
        }

        let blob_table_offset = self.blob_table_offset();
        let blob_table_size = self.blob_table_size() as u64;
        let blob_table_range = MetaRange::new(blob_table_offset, blob_table_size, false)?;
        if !blob_table_range.is_subrange_of(&meta_range)
            || blob_table_range.intersect_with(&inode_table_range)
        {
            return Err(einval!("invalid blob table offset or size."));
        }

        let ext_blob_table_offset = self.extended_blob_table_offset();
        let ext_blob_table_size =
            self.extended_blob_table_entries() as u64 * RAFSV5_EXT_BLOB_ENTRY_SIZE as u64;
        let ext_blob_table_range =
            MetaRange::new(ext_blob_table_offset, ext_blob_table_size, true)?;
        if ext_blob_table_size != 0
            && (!ext_blob_table_range.is_subrange_of(&meta_range)
                || ext_blob_table_range.intersect_with(&inode_table_range)
                || ext_blob_table_range.intersect_with(&blob_table_range))
        {
            return Err(einval!("invalid extended blob table offset or size."));
        }

        let prefetch_table_offset = self.prefetch_table_offset();
        let prefetch_table_size = self.prefetch_table_entries() as u64 * size_of::<u32>() as u64;
        let prefetch_table_range =
            MetaRange::new(prefetch_table_offset, prefetch_table_size, false)?;
        if prefetch_table_size != 0
            && (!prefetch_table_range.is_subrange_of(&meta_range)
                || prefetch_table_range.intersect_with(&inode_table_range)
                || prefetch_table_range.intersect_with(&blob_table_range)
                || (ext_blob_table_size != 0
                    && prefetch_table_range.intersect_with(&ext_blob_table_range)))
        {
            return Err(einval!("invalid prefetch table offset or size."));
        }

        Ok(())
    }
/// Validate the Rafs v5 super block.
Validate the Rafs v5 super block.
Validate the Rafs v5 super block .
pub fn validate(&self, meta_size: u64) -> Result<()> {
        if !self.is_rafs_v5() {
            return Err(einval!("invalid super block version number"));
        } else if self.sb_size() as usize != RAFSV5_SUPERBLOCK_SIZE
            || meta_size <= RAFSV5_SUPERBLOCK_SIZE as u64
        {
            return Err(einval!("invalid super block blob size"));
        } else if !self.block_size().is_power_of_two()
            || self.block_size() < 0x1000
            || (self.block_size() as u64 > RAFS_MAX_CHUNK_SIZE && self.block_size() != 4 << 20)
        {
            // Stargz has a special chunk size of 4MB.
            return Err(einval!("invalid block size"));
        } else if RafsSuperFlags::from_bits(self.flags()).is_none() {
            return Err(einval!("invalid super block flags"));
        }
        let meta_range = MetaRange::new(
            RAFSV5_SUPERBLOCK_SIZE as u64,
            meta_size - RAFSV5_SUPERBLOCK_SIZE as u64,
            true,
        )?;
        let inodes_count = self.inodes_count();
        let inode_table_offset = self.inode_table_offset();
        let inode_table_entries = self.inode_table_entries() as u64;
        let inode_table_size = inode_table_entries * size_of::<u32>() as u64;
        let inode_table_range = MetaRange::new(inode_table_offset, inode_table_size, false)?;
        if inodes_count > inode_table_entries || !inode_table_range.is_subrange_of(&meta_range) {
            return Err(einval!("invalid inode table count, offset or entries."));
        }
        let blob_table_offset = self.blob_table_offset();
        let blob_table_size = self.blob_table_size() as u64;
        let blob_table_range = MetaRange::new(blob_table_offset, blob_table_size, false)?;
        if !blob_table_range.is_subrange_of(&meta_range)
            || blob_table_range.intersect_with(&inode_table_range)
        {
            return Err(einval!("invalid blob table offset or size."));
        }
        let ext_blob_table_offset = self.extended_blob_table_offset();
        let ext_blob_table_size =
            self.extended_blob_table_entries() as u64 * RAFSV5_EXT_BLOB_ENTRY_SIZE as u64;
        let ext_blob_table_range =
            MetaRange::new(ext_blob_table_offset, ext_blob_table_size, true)?;
        if ext_blob_table_size != 0
            && (!ext_blob_table_range.is_subrange_of(&meta_range)
                || ext_blob_table_range.intersect_with(&inode_table_range)
                || ext_blob_table_range.intersect_with(&blob_table_range))
        {
            return Err(einval!("invalid extended blob table offset or size."));
        }
        let prefetch_table_offset = self.prefetch_table_offset();
        let prefetch_table_size = self.prefetch_table_entries() as u64 * size_of::<u32>() as u64;
        let prefetch_table_range =
            MetaRange::new(prefetch_table_offset, prefetch_table_size, false)?;
        if prefetch_table_size != 0
            && (!prefetch_table_range.is_subrange_of(&meta_range)
                || prefetch_table_range.intersect_with(&inode_table_range)
                || prefetch_table_range.intersect_with(&blob_table_range)
                || (ext_blob_table_size != 0
                    && prefetch_table_range.intersect_with(&ext_blob_table_range)))
        {
            return Err(einval!("invalid prefetch table offset or size."));
        }
        Ok(())
    }
pub fn validate ( & self , meta_size : u64 ) -> Result < ( ) > { if ! self . is_rafs_v5 ( ) { return Err ( einval ! ( " " ) ) ; } else if self . sb_size ( ) as usize != RAFSV5_SUPERBLOCK_SIZE || meta_size <= RAFSV5_SUPERBLOCK_SIZE as u64 { return Err ( einval ! ( " " ) ) ; } else if ! self . block_size ( ) . is_power_of_two ( ) || self . block_size ( ) < 0x1000 || ( self . block_size ( ) as u64 > RAFS_MAX_CHUNK_SIZE && self . block_size ( ) != 4 << 20 ) { // Stargz has a special chunk size of 4MB. return Err ( einval ! ( " " ) ) ; } else if RafsSuperFlags :: from_bits ( self . flags ( ) ) . is_none ( ) { return Err ( einval ! ( " " ) ) ; } let meta_range = MetaRange :: new ( RAFSV5_SUPERBLOCK_SIZE as u64 , meta_size - RAFSV5_SUPERBLOCK_SIZE as u64 , true , ) ? ; let inodes_count = self . inodes_count ( ) ; let inode_table_offset = self . inode_table_offset ( ) ; let inode_table_entries = self . inode_table_entries ( ) as u64 ; let inode_table_size = inode_table_entries * size_of :: < u32 > ( ) as u64 ; let inode_table_range = MetaRange :: new ( inode_table_offset , inode_table_size , false ) ? ; if inodes_count > inode_table_entries || ! inode_table_range . is_subrange_of ( & meta_range ) { return Err ( einval ! ( " " ) ) ; } let blob_table_offset = self . blob_table_offset ( ) ; let blob_table_size = self . blob_table_size ( ) as u64 ; let blob_table_range = MetaRange :: new ( blob_table_offset , blob_table_size , false ) ? ; if ! blob_table_range . is_subrange_of ( & meta_range ) || blob_table_range . intersect_with ( & inode_table_range ) { return Err ( einval ! ( " " ) ) ; } let ext_blob_table_offset = self . extended_blob_table_offset ( ) ; let ext_blob_table_size = self . extended_blob_table_entries ( ) as u64 * RAFSV5_EXT_BLOB_ENTRY_SIZE as u64 ; let ext_blob_table_range = MetaRange :: new ( ext_blob_table_offset , ext_blob_table_size , true ) ? ; if ext_blob_table_size != 0 && ( ! ext_blob_table_range . is_subrange_of ( & meta_range ) || ext_blob_table_range . intersect_with ( & inode_table_range ) || ext_blob_table_range . intersect_with ( & blob_table_range ) ) { return Err ( einval ! ( " " ) ) ; } let prefetch_table_offset = self . prefetch_table_offset ( ) ; let prefetch_table_size = self . prefetch_table_entries ( ) as u64 * size_of :: < u32 > ( ) as u64 ; let prefetch_table_range = MetaRange :: new ( prefetch_table_offset , prefetch_table_size , false ) ? ; if prefetch_table_size != 0 && ( ! prefetch_table_range . is_subrange_of ( & meta_range ) || prefetch_table_range . intersect_with ( & inode_table_range ) || prefetch_table_range . intersect_with ( & blob_table_range ) || ( ext_blob_table_size != 0 && prefetch_table_range . intersect_with ( & ext_blob_table_range ) ) ) { return Err ( einval ! ( " " ) ) ; } Ok ( ( ) ) }
Validate the Rafs v5 super block.
Validate the Rafs v5 super block .
&self
meta_size
u64
&self
meta_size
u64