cle
cle copied to clipboard
Loading DWARF fails
Description
I can't load debug info from a binary.
file: CWE121_Stack_Based_Buffer_Overflow__CWE193_char_alloca_cpy_72a.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
I get the following stack trace:
Python 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cle
>>> cle.Loader("/home/julius/Documents/ML/C/testcases/CWE121_Stack_Based_Buffer_Overflow/s01/CWE121_Stack_Based_Buffer_Overflow__CWE193_char_alloca_cpy_72a.o", load_debug_info=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/julius/Documents/ML/venv/lib/python3.11/site-packages/cle/loader.py", line 188, in __init__
self.initial_load_objects = self._internal_load(
^^^^^^^^^^^^^^^^^^^^
File "/home/julius/Documents/ML/venv/lib/python3.11/site-packages/cle/loader.py", line 782, in _internal_load
obj = self._load_object_isolated(main_spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/julius/Documents/ML/venv/lib/python3.11/site-packages/cle/loader.py", line 985, in _load_object_isolated
result = backend_cls(binary, binary_stream, is_main_bin=self._main_object is None, loader=self, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/julius/Documents/ML/venv/lib/python3.11/site-packages/cle/backends/elf/elf.py", line 208, in __init__
self._load_exception_handling(dwarf)
File "/home/julius/Documents/ML/venv/lib/python3.11/site-packages/cle/backends/elf/elf.py", line 620, in _load_exception_handling
lsda_exception_table = lsda.parse_lsda(entry.lsda_pointer, file_offset)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/julius/Documents/ML/venv/lib/python3.11/site-packages/cle/backends/elf/lsda.py", line 89, in parse_lsda
header = self._parse_lsda_header()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/julius/Documents/ML/venv/lib/python3.11/site-packages/cle/backends/elf/lsda.py", line 107, in _parse_lsda_header
lpstart = struct_parse(Struct("dummy", self._formats[base_encoding]("LPStart")), self.stream)["LPStart"]
~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 5
>>> cle.__version__
'9.2.84'
>>>
Loader works fine if i set load_debug_info=False.
Steps to reproduce the bug
import the attached binary with load_debug_info=True
import cle
cle.Loader("CWE121_Stack_Based_Buffer_Overflow__CWE193_char_alloca_cpy_72a.o", load_debug_info=True)
Environment
Python 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] on linux
Additional context
CWE121_Stack_Based_Buffer_Overflow__CWE193_char_alloca_cpy_72a.zip