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>
This commit introduces support for generating DWARF debug information
for binaries that LIEF cannot natively parse (e.g., raw firmware or unknown architectures).
Related to #1249
`std::numeric_limits<uint16_t>::max()` can conflict with `#define max`
defined by Windows in `minwindef.h`. Since we are in a public header,
forcing `NOMINMAX` should not be considered.
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>