Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Never return a section size smaller than virtual size #292

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/pe/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ fn section_read_size(section: &section_table::SectionTable, file_alignment: u32)
let size_of_raw_data = section.size_of_raw_data as usize;
let virtual_size = section.virtual_size as usize;
let read_size = {
let read_size = (section.pointer_to_raw_data as usize + size_of_raw_data + file_alignment
let read_size = ((section.pointer_to_raw_data as usize + size_of_raw_data + file_alignment
- 1)
& !(file_alignment - 1);
& !(file_alignment - 1)) - aligned_pointer_to_raw_data(section.pointer_to_raw_data as usize);
cmp::min(read_size, round_size(size_of_raw_data))
};

if virtual_size == 0 {
read_size
} else {
cmp::min(read_size, round_size(virtual_size))
}
cmp::max(read_size, round_size(virtual_size))
}

fn rva2offset(rva: usize, section: &section_table::SectionTable) -> usize {
Expand Down