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

Use reserved space footer for padding #84

Merged
merged 1 commit into from
May 15, 2024
Merged
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
14 changes: 11 additions & 3 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,9 @@ pub fn elf_to_tbf(

let footers_initial_len = binary_index - tbfheader.binary_end_offset() as usize;

// Flag to track if we are guaranteed to have a reserved space footer.
let mut ensured_footer_reserved_space: bool = false;

// Make sure the footer is at least the minimum requested size.
if (minimum_footer_size as usize) > footers_initial_len {
let mut needed_footer_reserved_space = (minimum_footer_size as usize) - footers_initial_len;
Expand All @@ -885,6 +888,10 @@ pub fn elf_to_tbf(

// Add reserved space to the footer.
binary_index += needed_footer_reserved_space;

// Since we ensured there is room for the reserved space footer, we mark
// that that footer will be created.
ensured_footer_reserved_space = true;
}

// Optionally calculate the additional padding needed to ensure the app size
Expand Down Expand Up @@ -917,9 +924,10 @@ pub fn elf_to_tbf(
binary_index += pad;

// If there is room for a TbfFooterCredentials we will use that.
if pad
>= (mem::size_of::<header::TbfHeaderTlv>()
+ mem::size_of::<header::TbfFooterCredentialsType>())
if ensured_footer_reserved_space
|| pad
>= (mem::size_of::<header::TbfHeaderTlv>()
+ mem::size_of::<header::TbfFooterCredentialsType>())
{
0
} else {
Expand Down
Loading