Skips `NOBITS` sections (like `.bss` and `.tbss`) when determining the last
section offset in `LIEF::ELF::Binary::last_offset_section()`.
Since these sections do not occupy space in the file, including them could lead to an unnecessary
increase in the final binary size.
This change addresses several issues related to ELF reconstruction.
It ensures compatibility with stricter loaders (like Android's linker)
and fix and issue with `STT_TLS` symbols
Resolve#1315
This commit implements the check_layout function for ELF binaries
similar to PE and Mach-O. This function aims to ensure that the
ELF binary is consistent according to various loader (e.g., Linux, Android)
The import thunk loop in Parser.tcc has no iteration limit and calls
peek_string_at() with no max length. A malformed PE with an unterminated
IAT causes the loop to process hundreds of thousands of fake entries,
each triggering multi-megabyte string reads — hanging indefinitely.
This is a DoS vector against any system using LIEF for PE analysis.
Fixes:
1. Cap the thunk loop at MAX_IMPORT_ENTRIES (65536) per DLL
2. Bound peek_string_at to MAX_IMPORT_NAME_SIZE (4096) bytes
3. Warn when the limit is hit so users know the IAT was truncated
Follows the existing pattern used by MAX_TLS_CALLBACKS and
MAX_RELOCATION_ENTRIES.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix bug with PE resources, where the PE builder will refuse to create a resources section if there are new resources but one does not exist
* Add test
---------
Co-authored-by: Romain Thomas <me@romainthomas.fr>
The in-page offset from the source segment is now kept, since changing
it may change the semantics of certain types of contents (e.g. ARM64
executable code relying on ADRP instructions).
Additionally, the virtual address of a segment is now properly aligned
in accordance with p_align instead of being hardcoded at the page size.
Fixes: d717340c9 ("Improve the logic of sections insertion in ELF binaries")
Co-authored-by: Thomas Wachter <thomas.wachter@huawei.com>