Skip to content

Commit

Permalink
pr: sanitize the footer version
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed Nov 30, 2023
1 parent 1b21e61 commit 251e28b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions accounts-db/src/tiered_storage/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub enum TieredStorageError {
#[error("invalid footer size: {0}, expected: {1}")]
InvalidFooterSize(u64, u64),

#[error("invalid footer version: {0}")]
InvalidFooterVersion(u64),

#[error("footer is unsanitary: {0}")]
SanitizeFooter(#[from] SanitizeFooterError),
}
13 changes: 10 additions & 3 deletions accounts-db/src/tiered_storage/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ impl TieredStorageFooter {
}

let mut footer_version: u64 = 0;
let mut magic_number = TieredStorageMagicNumber::zeroed();
file.read_type(&mut footer_version)?;
if footer_version != FOOTER_FORMAT_VERSION {
return Err(TieredStorageError::InvalidFooterVersion(footer_version));
}

let mut magic_number = TieredStorageMagicNumber::zeroed();
file.read_type(&mut magic_number)?;
if magic_number != TieredStorageMagicNumber::default() {
return Err(TieredStorageError::MagicNumberMismatch(
Expand All @@ -247,9 +251,12 @@ impl TieredStorageFooter {
));
}

let (_footer_version, offset) = get_type::<u64>(mmap, offset)?;
let (magic_number, _offset) = get_type::<TieredStorageMagicNumber>(mmap, offset)?;
let (footer_version, offset) = get_type::<u64>(mmap, offset)?;
if *footer_version != FOOTER_FORMAT_VERSION {
return Err(TieredStorageError::InvalidFooterVersion(*footer_version));
}

let (magic_number, _offset) = get_type::<TieredStorageMagicNumber>(mmap, offset)?;
if *magic_number != TieredStorageMagicNumber::default() {
return Err(TieredStorageError::MagicNumberMismatch(
TieredStorageMagicNumber::default().0,
Expand Down

0 comments on commit 251e28b

Please sign in to comment.