eliben / pyelftools

Parsing ELF and DWARF in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Modifed file pointer is not reset when _identify function in elffile.py raises exception

notgriffin opened this issue · comments

There is a case where the _identify function in elffile.py raises an exception, leaving the file pointer at 4.

self.stream.seek(0)
magic = self.stream.read(4)
elf_assert(magic == b'\x7fELF', 'Magic number does not match')

When this code is used with a shared file pointer and code that assumes the file pointer will be 0 a code path like when trying to create an ELFFile object, it can cause issues when the ending file pointer is not 0. On an exception, the file pointer should be reset to 0 and the exception reraised.