claird / PyPDF4

A utility to read and write PDFs with Python
obsolete-https://pythonhosted.org/PyPDF2/
Other
328 stars 61 forks source link

readFromStream(stream, pdf) receives None and pdf.strict fails #81

Open emelenas opened 4 years ago

emelenas commented 4 years ago

As stated in the title, pdf.strict in DictionaryObject.readFromStream (at line 667 in generic.py) raises an AttributeError because the parameter pdf as received is None.

Going back, this comes from ContentStream.__parseContentStream at file generic.py line 1027 though the call operands.append(readObject(stream, None)). readObject in turn calls DictionaryObject.readFromStream at line 65 of generic.py

Thus, it is an explicit call with None as an argument that causes the exception.

Anyhow if None is to be passed as argument pdf, I believe a check should be in order down the line to avoid exceptions.

I changed the call to

operands.append(readObject(stream, self.pdf))

and apparently no harm is done (aside from avoiding the exception).

Copied from https://github.com/mstamy2/PyPDF2/issues/563 since apparently no development there