elf: include path and sizes in "executable too short" error - #1404
Closed
gburd wants to merge 1 commit into
Closed
Conversation
When an ELF read runs past the end of the file, report the pathname, actual file size, and the required length instead of a bare message, so a truncated or mis-pathed binary is diagnosable from the failure.
nyh
approved these changes
Jun 30, 2026
There was a problem hiding this comment.
Pull request overview
Improves diagnosability of ELF load failures by expanding the "executable too short" error to include the pathname and size details, helping identify truncated or malformed binaries from logs alone.
Changes:
- Capture and report the ELF file path when the loader detects a short read.
- Include actual file size and required minimum length in the thrown
invalid_elf_error.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+330
to
338
| auto fsize = ::size(_f); | ||
| if (fsize < offset + size) { | ||
| char buf[256]; | ||
| snprintf(buf, sizeof(buf), | ||
| "executable too short %s: file_size=%lu need=%lu", | ||
| _pathname.c_str(), (unsigned long)fsize, | ||
| (unsigned long)(offset + size)); | ||
| throw osv::invalid_elf_error(buf); | ||
| } |
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.
Split out of #1399 per review (one PR per subsystem).
Adds the file path and the actual vs. expected sizes to the "executable too
short" error so a truncated or malformed object is diagnosable from the message
alone instead of just reporting that something was too short.
Build-qualified (kernel compile+link,
image=empty) on a binutils 2.44 /g++ 14.3.0 host.