Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Asserts when encountering invalid files

Open
#45 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
cli

Research direction

The reported entry point is /usr/bin/dlopen-notes, especially read_dlopen_notes and the argument loop around line 142. Start by tracing how filenames are opened and how invalid, missing, and directory inputs reach ELFFile. Add coverage for those inputs and verify the command avoids assertions as requested.

Written by the indexing model from the issue text.

Description

Version: 0.11-1
systemd: 256.9-1
kernel: 6.12.4-arch1-1

While writing a script to find all dl-opened libraries on a system, I ran into this assert when encountering .py files:

Traceback (most recent call last):
  File "/usr/bin/dlopen-notes", line 142, in <module>
    notes = [read_dlopen_notes(filename) for filename in args.filenames]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/dlopen-notes", line 24, in wrap
    return list(f(*args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/dlopen-notes", line 29, in read_dlopen_notes
    elffile = ELFFile(open(filename, 'rb'))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/elftools/elf/elffile.py", line 84, in __init__
    self._identify_file()
  File "/usr/lib/python3.12/site-packages/elftools/elf/elffile.py", line 570, in _identify_file
    elf_assert(magic == b'\x7fELF', 'Magic number does not match')
  File "/usr/lib/python3.12/site-packages/elftools/common/utils.py", line 80, in elf_assert
    _assert_with_exception(cond, msg, ELFError)
  File "/usr/lib/python3.12/site-packages/elftools/common/utils.py", line 143, in _assert_with_exception
    raise exception_type(msg)
elftools.common.exceptions.ELFError: Magic number does not match

Ideally, invalid & non-existent files (& directories) wouldn't cause asserts like this.

Dominant language
Python
Stars
28
Forks
15
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from systemd/package-notes

All issues in systemd/package-notes

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.