Skip to content

Commit

Permalink
Fix issue discovered by honggfuzzGptHeader::header_size is supposed…
Browse files Browse the repository at this point in the history
… to between, inclusive, 92 and the logical block size.Slice indexing goes out of range and panics if this isn't checked.Also check that it's enough for our GptHeader struct.
  • Loading branch information
DianaNites committed Oct 2, 2019
1 parent 2a9e14a commit d8ab05d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/gpt.rs
Expand Up @@ -78,6 +78,13 @@ fn check_validity<RS: Read + Seek>(
block_size: u64,
) -> Result<(), InnerError> {
ensure!(header.signature == EFI_PART, Signature);
ensure!(header.header_size >= 92, InvalidGptHeader);
// FIXME: This one shouldn't be a requirement.
ensure!(
header.header_size <= std::mem::size_of::<GptHeader>() as u32,
InvalidGptHeader
);
ensure!(header.header_size <= block_size as u32, InvalidGptHeader);
let old_crc = std::mem::replace(&mut header.header_crc32, 0);
let crc = calculate_crc(header);
header.header_crc32 = old_crc;
Expand Down

0 comments on commit d8ab05d

Please sign in to comment.