← 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

⚠️ This summary may be outdated — the issue content or evaluation prompts have changed since this evaluation was made.

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.

Suggested action:

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
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

No update history recorded yet.

Related issues

Issue Project State Summary Similarity
#1752766 Snapcraft fails to prime part containg device files snapcraft (launchpad) closed Closed without a direct fix. Snapcraft crashes when priming parts with device files, throwing an OSError during ELF detection. The bug was likely abandoned or resolved in newer Snapcraft versions.
80%
#1795171 snapcraft fail to find built executable under prime $SNAP snapcraft (launchpad) closed Closed without resolution or comments, likely abandoned. The issue reported a FileNotFoundError when Snapcraft failed to expand the $SNAP variable in the prime directory path during build.
75%
#2830 elf: properly handle corrupted ELF files snapcraft merged Merged. Snapcraft now catches errors and issues warnings instead of crashing during priming when encountering corrupted ELF files. Test binaries from Qt 5.13 were added, and commits were squashed with source attribution included per reviewer feedback.
74%
#1627781 Snapcraft should use "prime" keyword instead of "snap" snapcraft (launchpad) closed Closed without resolution. Snapcraft 2.17's lack of support for the prime keyword was superseded by newer versions. No comments or fixes were applied.
73%
#1907721 Snapcraft broken on ARM64 snapcraft (launchpad) closed Closed without comments. No fix or merge was applied. The ARM64 Multipass QEMU error and YAML !PrimeState deserialization bug were likely resolved by upstream Snapcraft updates or abandoned.
71%
#1854458 snapcraft comes with an old version of pyelftools, some builds fail due to this snapcraft (launchpad) closed Closed without resolution. The issue stemmed from an outdated pyelftools dependency triggering a Unicode decode error during ELF parsing. No patch was applied, leaving the snap build failure unresolved.
71%