joxeankoret / pyew

Official repository for Pyew.
GNU General Public License v2.0
383 stars 95 forks source link

Elf objects initialized by a binary string (as opposed to filename) cause traceback #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Try to load an Elf object using a binary string. E.g.:

>>> from pyew.Elf import Elf
>>> data = file("/bin/ls").read()
>>> Elf(data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pyew/Elf/__init__.py", line 77, in __init__
    if os.path.exists(initstr):
  File "MY_VIRTUALENV_PATH/lib/python2.6/genericpath.py", line 18, in exists
    st = os.stat(path)
<type 'exceptions.TypeError'>: stat() argument 1 must be encoded string without 
NULL bytes, not str

What is the expected output? What do you see instead?

The problem comes from the fact that the initializer is using os.path.exists() 
to determine if the passed in string is a filename that should be loaded or is 
otherwise considered a string containing already loaded bytes. The problem 
though is that os.path.exists() chokes on characters that aren't 
expected/allowed to be part of a filename (such a 0x00).

What version of the product are you using? On what operating system?

Latest pyew checkout, on Ubuntu Linux (9.10 and 10.04).

Please provide any additional information below.

Attached is a small patch that fixes this issue.

Original issue reported on code.google.com by wamc...@gmail.com on 1 Jul 2010 at 7:37

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for reporting! I applied your patch.

Original comment by joxean.p...@gmail.com on 2 Jul 2010 at 8:49