← Back to issue list

snapcraft prime fails if it finds an invalid ELF file

View original Launchpad issue

Metadata

Project
snapcraft (launchpad)
Number
#1838098
Type
issue
State
closed
Author
~tdaitx
Labels
—
Created
Updated
Closed

Current evaluation

Snapcraft now skips invalid ELF files during priming; PR #2663 was merged in commit 89490853e.

Resolution: closed resolved

Reason: PR snapcore/snapcraft#2663 added handling for ELFError so malformed ELF files are ignored instead of aborting prime. The change is recorded in commit 89490853e.

Evaluated by: mr-cal-bot

No scores available.

Issue body

While priming a proprietary testsuite snapcraft bailed out when it got an exception due to an invalid ELF file. This is the traceback: Traceback (most recent call last): File "/snap/snapcraft/3059/bin/snapcraft", line 11, in <module> load_entry_point('snapcraft==3.6', 'console_scripts', 'snapcraft')() File "/snap/snapcraft/3059/lib/python3.5/site-packages/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) File "/snap/snapcraft/3059/lib/python3.5/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/snap/snapcraft/3059/lib/python3.5/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/cli/_command.py", line 82, in invoke return super().invoke(ctx) File "/snap/snapcraft/3059/lib/python3.5/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/snap/snapcraft/3059/lib/python3.5/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/cli/lifecycle.py", line 274, in snap _execute(steps.PRIME, parts=[], pack_project=True, output=output, **kwargs) File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/cli/lifecycle.py", line 79, in _execute lifecycle.execute(step, project_config, parts) File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 94, in execute executor.run(step, part_names) File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 148, in run self._handle_step(part_names, part, step, current_step, cli_config) File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 162, in _handle_step getattr(self, "_run_{}".format(current_step.name))(part) File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 237, in _run_prime self._run_step(step=steps.PRIME, part=part, progress="Priming") File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 281, in _run_step getattr(part, step.name)() File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 778, in prime self._runner.prime() File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/_runner.py", line 91, in prime "override-prime", self._override_prime_scriptlet, self._primedir File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/_runner.py", line 137, in _run_scriptlet scriptlet_name, function_call.strip() File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/_runner.py", line 193, in _handle_builtin_function function(**function_args) File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 790, in _do_prime dependency_paths = self._handle_elf(snap_files) File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 797, in _handle_elf elf_files = elf.get_elf_files(self.primedir, snap_files) File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/elf.py", line 571, in get_elf_files elf_file = ElfFile(path=path) File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/elf.py", line 218, in __init__ elf_data = self._extract(path) File "/snap/snapcraft/3059/lib/python3.5/site-packages/snapcraft/internal/elf.py", line 234, in _extract elf = elftools.elf.elffile.ELFFile(fp) File "/snap/snapcraft/3059/lib/python3.5/site-packages/elftools/elf/elffile.py", line 61, in __init__ self._identify_file() File "/snap/snapcraft/3059/lib/python3.5/site-packages/elftools/elf/elffile.py", line 237, in _identify_file raise ELFError('Invalid EI_CLASS %s' % repr(ei_class)) elftools.common.exceptions.ELFError: Invalid EI_CLASS b'\x00' The file header has an invalid class for an ELF file (it is not supposed to be valid, this is to be used by a testsuite): $ od -An -tx1 -N5 <offending file> 7f 45 4c 46 00 Expected result: snapcraft should ignore the ELFError as this is not a valid ELF file. https://github.com/snapcore/snapcraft/blob/master/snapcraft/internal/elf.py#L571 should be modified to catch the ELFError and continue processing the next file on the list.

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved Snapcraft now skips invalid ELF files during priming; PR #2663 was merged in commit 89490853e.
stealth/space-bunny-alpha — closed resolved Fixed by merged PR #2663 (commit 89490853e): Snapcraft now skips invalid ELF files during priming and continues processing.
stealth/space-bunny-alpha — closed resolved Fixed in commit 89490853e (“elf: handle invalid elf files”), which prevents malformed ELF test files from aborting prime.
qwen/qwen3.6-35b-a3b — — Abandoned without fix. Snapcraft prime crashes on invalid ELF files due to an unhandled ELFError. No pull request or resolution was provided.
qwen/qwen3.6-35b-a3b — — Closed without a fix. Snapcraft prime crashed on invalid ELF files due to an uncaught ELFError. With zero comments and no PR, the report was abandoned or superseded by newer versions handling malformed binaries gracefully.
qwen/qwen3.6-35b-a3b — — Closed without documented resolution or comments. The report detailed snapcraft crashing on invalid ELF files during priming and suggested catching ELFError. No fix or official resolution was recorded.
qwen3.6-35b-a3b-mtp-q6 — — Closed without resolution. Snapcraft crashed during prime on invalid ELF files due to an unhandled ELFError. The suggested fix was to catch the exception in elf.py and skip invalid files. No fix was implemented.

Update history

Date Change
created

Related work

  • Likely Fixed By: snapcore/snapcraft#2663 (confidence 99%)

    The linked fix PR was merged as commit 89490853e, titled "elf: handle invalid elf files".

Related issues

Issue Project State Summary Similarity
#1752766 Snapcraft fails to prime part containg device files snapcraft (launchpad) closed Merged PR #1976 (commit ef3309f3c) fixed device-node priming by limiting ELF inspection to regular files and symlinks.
78%
#2830 elf: properly handle corrupted ELF files snapcraft merged Merged #2830 as commit 727ffbdb0, making Snapcraft warn and continue when corrupted ELF files are encountered during priming.
76%
#1854458 snapcraft comes with an old version of pyelftools, some builds fail due to this snapcraft (launchpad) closed Fixed ELF prime-time crashes from non-ASCII section names in snapcore/snapcraft#2830; maintainers confirmed the fix shipped as part of Snapcraft 3.10.
76%
#1843 elf: warn if primed files will not work with the base's linker snapcraft merged Merged PR #1843 (commit 42023dfaa) added ELF parsing of primed files in snapcraft/internal/elf.py, warning when a file's required glibc version is incompatible with the base's linker. Closes issue #1667.
75%
#1757094 snapcraft in edge channel (2.39.2+git46.c22d7e2) fails to cross-compile kernel snapcraft (launchpad) closed Cross-compile priming was fixed by snapcore/snapcraft#2012, merged as eae356003, skipping ELF dependency and linker checks for non-app snaps such as kernel snaps.
71%