Cannot hash Section
Dragorn421 opened this issue · comments
Using pyelftools 0.30
The Section type isn't hashable despite defining a __hash__
method
Or more correctly, because of that method it is not hashable. The method raises an error.
File ".../elftools/elf/sections.py", line 126, in __hash__
return hash(self.header)
^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'Container'
Reproduce
pip install pyelftools==0.30
- get an elf file. For example
echo | as
to produce aa.out
elf (assuming elf unix-y system) - run the following script:
from elftools.elf.elffile import ELFFile
with open("a.out", "rb") as f:
elf = ELFFile(f)
sections = set(elf.iter_sections())
- observe error
Traceback (most recent call last):
File ".../test_pyelftools_section_hash.py", line 5, in <module>
sections = set(elf.iter_sections())
^^^^^^^^^^^^^^^^^^^^^^^^
File ".../elftools/elf/sections.py", line 126, in __hash__
return hash(self.header)
^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'Container'
Suggested fix
Just remove Section.__hash__
and use default "id()"-based hashing.
For example Symbol
also doesn't have a __hash__
(but neither a __eq__
which Section does define)