Skip to content

elf: include path and sizes in "executable too short" error - #1404

Closed
gburd wants to merge 1 commit into
cloudius-systems:masterfrom
gburd:pr/elf-short-error
Closed

elf: include path and sizes in "executable too short" error#1404
gburd wants to merge 1 commit into
cloudius-systems:masterfrom
gburd:pr/elf-short-error

Conversation

@gburd

@gburd gburd commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

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.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread core/elf.cc
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);
}
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.

3 participants