Skip to content

Commit

Permalink
Merge pull request #93 from Swiftb0y/pdb-skip-invalid-pages
Browse files Browse the repository at this point in the history
fix(pdb): skip reading rows of invalid pages
  • Loading branch information
Holzhaus committed Oct 13, 2022
2 parents a2fc285 + 32bc3ff commit db59ea4
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/pdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ impl Header {
}
}

#[binrw]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
struct PageFlags(u8);

impl PageFlags {
#[must_use]
pub fn page_has_data(&self) -> bool {
(self.0 & 0x40) == 0
}
}

/// A table page.
///
/// Each page consists of a header that contains information about the type, number of rows, etc.,
Expand Down Expand Up @@ -234,7 +245,7 @@ pub struct Page {
///
/// According to [@flesniak](https://github.com/flesniak):
/// > strange pages: 0x44, 0x64; otherwise seen: 0x24, 0x34
pub page_flags: u8,
page_flags: PageFlags,
/// Free space in bytes in the data section of the page (excluding the row offsets in the page footer).
pub free_size: u16,
/// Used space in bytes in the data section of the page.
Expand Down Expand Up @@ -287,7 +298,7 @@ pub struct Page {
page_heap_offset: u64,
/// Row groups belonging to this page.
#[br(seek_before(row_groups_offset), restore_position)]
#[br(parse_with = Self::parse_row_groups, args(page_type, page_heap_offset, num_rows, num_row_groups))]
#[br(parse_with = Self::parse_row_groups, args(page_type, page_heap_offset, num_rows, num_row_groups, page_flags))]
pub row_groups: Vec<RowGroup>,
}

Expand All @@ -299,10 +310,10 @@ impl Page {
fn parse_row_groups<R: Read + Seek>(
reader: &mut R,
ro: &ReadOptions,
args: (PageType, u64, u16, u16),
args: (PageType, u64, u16, u16, PageFlags),
) -> BinResult<Vec<RowGroup>> {
let (page_type, page_heap_offset, num_rows, num_row_groups) = args;
if num_row_groups == 0 {
let (page_type, page_heap_offset, num_rows, num_row_groups, page_flags) = args;
if num_row_groups == 0 || !page_flags.page_has_data() {
return Ok(vec![]);
}

Expand Down Expand Up @@ -338,7 +349,7 @@ impl Page {
#[must_use]
/// Returns `true` if the page actually contains row data.
pub fn has_data(&self) -> bool {
(self.page_flags & 0x40) == 0
self.page_flags.page_has_data()
}

#[must_use]
Expand Down

0 comments on commit db59ea4

Please sign in to comment.