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

MAINT: Throw PdfReadError if Trailer can't be read #1298

Merged
merged 11 commits into from Aug 31, 2022
Merged
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Expand Up @@ -12,6 +12,7 @@ history and [GitHubs 'Contributors' feature](https://github.com/py-pdf/PyPDF2/gr
## Contributors to the pyPdf / PyPDF2 project

* [DL6ER](https://github.com/DL6ER)
* [ediamondscience](https://github.com/ediamondscience)
* [JianzhengLuo](https://github.com/JianzhengLuo)
* [Karvonen, Harry](https://github.com/Hatell/)
* [KourFrost](https://github.com/KourFrost)
Expand Down
7 changes: 5 additions & 2 deletions PyPDF2/_reader.py
Expand Up @@ -326,8 +326,11 @@ def metadata(self) -> Optional[DocumentInformation]:
return None
obj = self.trailer[TK.INFO]
retval = DocumentInformation()
retval.update(obj) # type: ignore
return retval
if isinstance(obj, type(None)) is True:
ediamondscience marked this conversation as resolved.
Show resolved Hide resolved
raise PdfReadError("trailer not found or does not point to document information directory")
else:
retval.update(obj) # type: ignore
return retval
MartinThoma marked this conversation as resolved.
Show resolved Hide resolved

def getDocumentInfo(self) -> Optional[DocumentInformation]: # pragma: no cover
"""
Expand Down