Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot hash Section #539

Open
Dragorn421 opened this issue Feb 11, 2024 · 0 comments
Open

Cannot hash Section #539

Dragorn421 opened this issue Feb 11, 2024 · 0 comments

Comments

@Dragorn421
Copy link

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

  1. pip install pyelftools==0.30
  2. get an elf file. For example echo | as to produce a a.out elf (assuming elf unix-y system)
  3. 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())
  1. 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant