Skip to content

Commit 3933176

Browse files
committed
loader: handle SegmentationViolation for malformed ELF files
When processing malformed ELF files with invalid relocations, vivisect raises envi.exc.SegmentationViolation during relocation processing. This change catches these exceptions and converts them to CorruptFile exceptions with helpful error messages instead of crashing with a traceback. Fixes #2794
1 parent cbd6d2a commit 3933176

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
### Bug Fixes
3838

39+
- loader: gracefully handle malformed ELF files with invalid relocations @kami922 #2794
3940
- binja: fix a crash during feature extraction when the MLIL is unavailable @xusheng6 #2714
4041

4142
### capa Explorer Web

capa/loader.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from typing import Optional
2121
from pathlib import Path
2222

23+
import envi.exc
2324
from rich.console import Console
2425
from typing_extensions import assert_never
2526

@@ -175,6 +176,9 @@ def get_workspace(path: Path, input_format: str, sigpaths: list[Path]):
175176
vw = viv_utils.getShellcodeWorkspaceFromFile(str(path), arch="amd64", analyze=False)
176177
else:
177178
raise ValueError("unexpected format: " + input_format)
179+
except envi.exc.SegmentationViolation as e:
180+
# Malformed binary with invalid memory references (e.g., broken ELF relocations)
181+
raise CorruptFile(f"Invalid memory access during binary parsing: {e}") from e
178182
except Exception as e:
179183
# vivisect raises raw Exception instances, and we don't want
180184
# to do a subclass check via isinstance.

0 commit comments

Comments
 (0)