Skip to content

Commit

Permalink
MachO::Binary::extend_section fill gap by default
Browse files Browse the repository at this point in the history
The previous implementation extended section by strictly requested
amount, possibly creating a gap in case we needed to satisfy alignment
requirements.

However, information about the size of the gap is lost, and not trivial
to recover. This patch changes `extend_section` to extend section by
more than requested to avoid creating the gap.
  • Loading branch information
DzenIsRich authored and romainthomas committed Jan 11, 2025
1 parent 60de925 commit 9a4f609
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions include/LIEF/MachO/Binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,9 @@ class LIEF_API Binary : public LIEF::Binary {
bool extend_segment(const SegmentCommand& segment, size_t size);

/// Extend the **content** of the given Section.
/// @note This method may create a gap between the current section and the next one, if `size`
/// is not multiple of the maximum alignment of sections before the current one.
/// @note This method may extend the section more than `size` preventing creation a gap
/// between the current section and the next one.
/// This may happen trying to satisfy alignment requirement of sections.
/// @note This method works only with sections that belong to the first segment.
bool extend_section(Section& section, size_t size);

Expand Down
2 changes: 1 addition & 1 deletion src/MachO/Binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ bool Binary::extend_section(Section& section, size_t size) {
}

// Extend the given `section`.
section.size(section.size() + size);
section.size(section.size() + shift_value);

return true;
}
Expand Down

0 comments on commit 9a4f609

Please sign in to comment.