Skip to content

Commit

Permalink
Fix ReadExt4SuperBlock function (#1229)
Browse files Browse the repository at this point in the history
Previously the function would read bytes from a given file
and convert them into internal ext4 super block object,
without checking that the read bytes are actually ext4
super block.
Fix the behavior by checking ext4 super block magic.

Signed-off-by: Maksim An <[email protected]>
  • Loading branch information
anmaxvl authored Nov 23, 2021
1 parent dccc62d commit f52c346
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext4/tar2ext4/tar2ext4.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ func ReadExt4SuperBlock(vhdPath string) (*format.SuperBlock, error) {
if err := binary.Read(vhd, binary.LittleEndian, &sb); err != nil {
return nil, err
}
// Make sure the magic bytes are correct.
if sb.Magic != format.SuperBlockMagic {
return nil, errors.New("not an ext4 file system")
}
return &sb, nil
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f52c346

Please sign in to comment.