Skip to content

Asserts when encountering invalid files #45

@Winterhuman

Description

@Winterhuman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions