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

Variable referenced before assignment + index out of range #26

Closed
decalage2 opened this issue Mar 31, 2015 · 2 comments
Closed

Variable referenced before assignment + index out of range #26

decalage2 opened this issue Mar 31, 2015 · 2 comments

Comments

@decalage2
Copy link
Owner

Originally reported by: Meni Farjon (Bitbucket: solebitlabs_meni_farjon, GitHub: Unknown)


Hi,
First of all thanks for the huge work.
I've encountered a variable reference error + an index out of range while using olefile.py.

Trace:

#!text
Traceback (most recent call last):
  File "/libs/olefile.py", line 2103, in getproperties
    s = b"****" + fp.read(i32(fp.read(4))-4)
  File "/libs/olefile.py", line 493, in i32
    return i8(c[o]) | (i8(c[o+1])<<8) | (i8(c[o+2])<<16) | (i8(c[o+3])<<24)
IndexError: index out of range

During handling of the above exception, another exception occurred:

#!text
Traceback (most recent call last):
  File "/ole2_compound/ole2_compound.py", line 45, in decode
    if is_encoded(data):
  File "/ole2_compound/ole2_compound.py", line 274, in is_encoded
    office_type, office_properties = detect_office_file_type(ole)
  File "/ole2_compound/ole2_compound.py", line 92, in detect_office_file_type
    properties = ole.getproperties(['\x05SummaryInformation'])
  File "/libs/olefile.py", line 2112, in getproperties
    self._raise_defect(DEFECT_INCORRECT, msg, type(exc))
UnboundLocalError: local variable 'type' referenced before assignment

Attached is the xls file causing the errors. (310445.xls)
Using python 3.2.
olefile version 0.42 2015-01-25

Thanks!


@decalage2
Copy link
Owner Author

Original comment by Philippe Lagadec (Bitbucket: decalage, GitHub: decalage2):


Same issue reported by Ross Spencer:

Line 2213 you're trying to access the function type() e.g. type(exc) but previously, line 2120 you create a variable called type e.g. type = i32(s, offset), this is overriding your ability to access the function at the exception point.

#!text
  File "C:\Working\git\oletools\oletools\thirdparty\olefile\olefile.py", line 2212, in getproperties
    self._raise_defect(DEFECT_INCORRECT, msg, type(exc))
UnboundLocalError: local variable 'type' referenced before assignment 

Solution: rename the local variable "type" to property_type.

@decalage2
Copy link
Owner Author

Original comment by Philippe Lagadec (Bitbucket: decalage, GitHub: decalage2):


fixed issue #26 in OleFileIO.getproperties (was using id and type as local variable names)

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

No branches or pull requests

1 participant