Variable referenced before assignment + index out of range #26

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

Projects

None yet

1 participant

@decalage2
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
Owner

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
Owner

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


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

@decalage2 decalage2 closed this May 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment