Skip to content

bug with file object #8

@decalage2

Description

@decalage2

Originally reported by: Philippe Lagadec (Bitbucket: decalage, GitHub: decalage2)


reported on http://www.decalage.info/en/python/olefileio#comment-481

I passed a file() to OleFileIO() and got an error in this line 979:
filesize = os.path.getsize(filename)
but in line 847 you check for a file object
if hasattr(filename, 'read'):

Potential solutions:

  • use name method of file object before calling getsize (only works with real files)
  • use seek(os.SEEK_END) then tell (only works with seekable file objects)
  • do not allow file-like objects
  • read all data then check len

I think the seek/tell solution is the most appropriate, since other parts of the code require seekable file objects anyway. Non-seekable file objects could be read into memory and converted to a StringIO beforehand.


Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions