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

Fix sorting in MachO::Binary::extend_section, rework extend_section tests #1152

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DzenIsRich
Copy link
Contributor

See individual commit messages.

If there are empty sections and non-empty section at the same offset, we
want to shift only empty sections.

The expected behavior is that we sort sections in ascending order, and
then `sections_to_shift` is trimmed, such that the last element becomes
`section`.

Previously, we were sorting in descending order, while keeping empty
sections in the same order. Due to this we were doing trimming
incorrectly.
The previous implementation of the test was expecting unsupported
behavior from LIEF.

LIEF currently does not support arbitrary calls to add_section and
extend_section and keeping the layout of the binary correct.
Currently it is responsibility of a user to ensure that the final layout
of the binary is well-formed.

This patch splits test into two cases:
1. Repeated calls to add_section followed by extend_section using
   different alignment values.
2. Multiple calls to add_section and then multiple calls to
   extend_section using the same alignment values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant