Repository navigation
Conversation
…section Some binaries (e.g. Heroes3.exe, see revng#598) carry a Load Config Table data directory whose RVA does not fall within any section -- typically a stale entry left by an older or non-standard linker that never actually emitted a load config directory. `COFFObjectFile::initLoadConfigPtr()` resolves this directory eagerly while llvm::object::createBinary constructs the COFFObjectFile, and fails to open the file at all if it's malformed this way, even though the rest of the binary may otherwise be usable. Since revng's own PECOFFImporter never gets a chance to run in that case, this is not something revng's importer logic can work around after the fact. Add sanitizeCOFFLoadConfigDirectory(), which parses just enough of the raw PE/COFF header by hand (mirroring the exact section-coverage check COFFObjectFile::getRvaPtr performs) to detect this one specific situation ahead of calling createBinary, and neutralizes the offending directory entry in a patched copy of the buffer if found -- i.e. treats it as absent, which is what happens whenever RelativeVirtualAddress == 0 anyway. This avoids requiring a patched LLVM dependency, since revng builds against whatever LLVM `find_package(LLVM)` finds. Well-formed binaries are left byte-for-byte untouched. This intentionally only covers the Load Config Table, not the other data directories COFFObjectFile resolves eagerly (import, delay-import, export, base relocation, debug, TLS): unlike load config, revng's PECOFFImporter actively consumes import/delay-import directory contents to build the model's imported functions, so silently dropping those would change import information rather than just tolerating a stale, unused directory. Co-Authored-By: Claude Sonnet 5 <[email protected]>
sjkim1127
force-pushed
the
fix/coff-dangling-data-directory-rva
branch
from
September 18, 2026 01:20
8e3e698 to
de187e6
Compare
Contributor
|
Hi, we didn't manage to triage the original issue. There have been some changes around that area recently, so I want to take a moment to review it before considering this PR. In case you closed this PR due to the lack of answer: we're off on the weekend |
sjkim1127
marked this pull request as ready for review
September 21, 2026 14:52
sjkim1127
marked this pull request as draft
September 21, 2026 14:55
Author
|
Thanks for reopening the PR and for the clarification — no worries about the weekend :) I’ll leave it open as a draft while you triage #598 and review the recent changes in this area. I’ve also pushed a small follow-up commit adding the optional-header bounds check, a PE32+ regression test, and a malformed I’ll hold off on further changes until you’ve had a chance to review. Thanks for taking the time! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Fixes #598.
revng analyze import-binaryfails outright on some real-world PE/COFF binaries (e.g.Heroes3.exefrom the issue) with:Root cause
This is not a bug in revng's
PECOFFImporter. The error is raised byllvm::object::createBinaryitself, before revng's own importer code ever runs.COFFObjectFile::initialize()(inllvm/lib/Object/COFFObjectFile.cpp) eagerly resolves several data directories while constructing the object file, including the Load Config Table. If a directory's RVA doesn't fall inside any section,getRvaPtrreturns a hardparse_failederror ("RVA 0x... for <directory> not found"), whichCOFFObjectFile::initialize()propagates —ignoreStrippedErrorsonly swallows the different, already-handled case of an RVA that's inside a section but pastSizeOfRawData. SocreateBinaryfails and the file can't be opened at all, even though everything else about it may be fine.This happens in practice with binaries from older/non-standard linkers that leave a stale RVA in the load config directory instead of zeroing it when the directory isn't actually used.
revng builds against whatever LLVM
find_package(LLVM)finds, so patching this specific check into a private LLVM fork isn't something this PR does — the fix below is a revng-local workaround that avoids needing one.Fix
lib/Model/Importer/Binary/COFFDataDirectorySanitizer.haddssanitizeCOFFLoadConfigDirectory(), called fromBinaryImporter.cppbeforeobject::createBinary. It parses the raw buffer by hand (DOS header → PE signature → COFF header → optional header → load config data directory entry → section table, all with explicit bounds checks) and checks whether the Load Config Table's RVA falls inside[VirtualAddress, VirtualAddress + VirtualSize)of some section — mirroring the exact checkCOFFObjectFile::getRvaPtrperforms. If it doesn't, we zero out that one directory entry's RVA/Size in a patched copy of the buffer (i.e., treat it as absent) and log what we dropped via-debug=binary-importer. Well-formed binaries are left byte-for-byte untouched (function returnsnullptr).Scope: this intentionally only covers the Load Config Table, not the other directories
COFFObjectFileresolves eagerly (import, delay-import, export, base relocation, debug, TLS), even though they share the exact same failure mode. Unlike load config, revng'sPECOFFImporteractively consumes the import/delay-import directories to build the model's imported functions — silently dropping those would change import information in the resulting model rather than just tolerating a stale, unused directory. If a real binary turns up needing one of the others, I'd rather extend this with a concrete repro than guess at the scope now.Validation
tests/unit/COFFDataDirectorySanitizer.cpp(registered intests/unit/CMakeLists.txtastest_coff_data_directory_sanitizer), which builds a minimal synthetic PE32 in memory and checks: a Load Config RVA outside the only section makescreateBinaryfail before the patch and succeed after it; a valid Load Config RVA and a binary with no load config directory at all are both left untouched by the sanitizer; a handful of non-PE/truncated buffers don't crash it.revng analyze import-binaryend-to-end against the reporter'sHeroes3.exe. What I did verify: I compiled the header and this exact test file standalone against Homebrew's LLVM 22 and Boost 1.92 (samellvm::object/llvm::COFFstruct layouts, different LLVM version than whatever revng pins) — all 4 test cases pass, including under ASan+UBSan, and the standalone build is clean under-Wall -Wextra -Wpedantic.Heroes3.exe(proprietary game binary behind a Google Drive link).Limitations / what's left
Heroes3.exe— I'd like to do both (or have a maintainer do so) before this comes out of draft.🤖 Generated with Claude Code