rarmknecht / peepdf

Automatically exported from code.google.com/p/peepdf
GNU General Public License v3.0
0 stars 0 forks source link

UnboundLocalError: local variable 'ret' referenced before assignment in PDFFilters.py #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When processing certain files, peepdf crashes with the following error:

UnboundLocalError: local variable 'ret' referenced before assignment

The bug lies in the PDFFilters.py file in the decodeStream() function, line 92:

{{{
    Traceback (most recent call last):
      File "my_script.py", line 45, in <module>
        ret, pdf = PDFCore.PDFParser().parse(filepath, True, True)
      File "/home/travesti/peepdf_0.2/PDFCore.py", line 6727, in parse
        ret = body.updateObjects()
      File "/home/travesti/peepdf_0.2/PDFCore.py", line 4126, in updateObjects
        object.resolveReferences()
      File "/home/travesti/peepdf_0.2/PDFCore.py", line 2470, in resolveReferences
        ret = self.decode()
      File "/home/travesti/peepdf_0.2/PDFCore.py", line 2001, in decode
        ret = decodeStream(self.encodedStream, self.filter.getValue(), self.filterParams)
      File "/home/travesti/peepdf_0.2/PDFFilters.py", line 92, in decodeStream
        return ret
    UnboundLocalError: local variable 'ret' referenced before assignment
}}}

The exception is raised because there isn't a previous declaration of the "ret" 
variable in the decodeStream() function. If none of the conditions are true 
then the "ret" variable never gets a value, the function ret is reached and 
Python raises the UnboundLocalError exception.

I patched the function just adding the following line at the begenning of the 
decodeStream() function:

{{{
    ret = (-1, "")
}}}

But it keeps raising errors in other modules :(

Original issue reported on code.google.com by poxyran...@gmail.com on 8 Mar 2014 at 3:11

GoogleCodeExporter commented 9 years ago
Hi! Thanks a lot for opening the issue! Can you send me a PDF sample to peepdf 
AT eternal-todo DOT com, please? Then I can confirm the bug (but I see the 
error) and do some tests, because the main issue is that the filter is not a 
normal one, so there should be another root problem...

Original comment by josemigu...@gmail.com on 8 Mar 2014 at 12:23

GoogleCodeExporter commented 9 years ago
Fixed in r229

Original comment by josemigu...@gmail.com on 15 Jun 2014 at 4:37