Skip to content

Fix missing null check for file read in binary parser#3

Open
prjanitor wants to merge 1 commit intolowRISC:masterfrom
prjanitor:prjanitor/cbf346814399b1b6ff529174ad8d509dac4bc712
Open

Fix missing null check for file read in binary parser#3
prjanitor wants to merge 1 commit intolowRISC:masterfrom
prjanitor:prjanitor/cbf346814399b1b6ff529174ad8d509dac4bc712

Conversation

@prjanitor
Copy link
Copy Markdown

Summary

This PR fixes a bug in the get_elf_header function in binary_parser.cc where the file read operation was not verified before accessing the header contents.

Changes

  • Added a check after file.read() to verify:

    1. The file stream is in a good state (!file)
    2. The expected number of bytes were read (file.gcount() != sizeof(Elf64_Ehdr))
  • Throws a descriptive std::runtime_error if the read fails

Impact

This prevents undefined behavior when processing corrupted or empty ELF files, providing a clear error message instead of potentially crashing or producing incorrect results.


This PR was generated by PRJanitor — an automated tool that finds and fixes small bugs in open-source projects.

We respect your contribution guidelines — if your project doesn't accept bot PRs, we won't send more. You can also add a .github/prjanitor.yml file with enabled: false to opt out explicitly.

The get_elf_header function now verifies that the file read operation succeeded
before accessing the header contents. This prevents undefined behavior when
processing corrupted or empty ELF files.
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.

1 participant