Merge pull request #4683 from cool-RR/2020-06-12-raise-from

Fix exception causes in PdfParser.py
This commit is contained in:
Andrew Murray 2020-06-21 15:19:14 +10:00 committed by GitHub
commit 5962c2e797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -251,8 +251,8 @@ class PdfDict(collections.UserDict):
def __getattr__(self, key): def __getattr__(self, key):
try: try:
value = self[key.encode("us-ascii")] value = self[key.encode("us-ascii")]
except KeyError: except KeyError as e:
raise AttributeError(key) raise AttributeError(key) from e
if isinstance(value, bytes): if isinstance(value, bytes):
value = decode_text(value) value = decode_text(value)
if key.endswith("Date"): if key.endswith("Date"):
@ -811,11 +811,11 @@ class PdfParser:
if m: if m:
try: try:
stream_len = int(result[b"Length"]) stream_len = int(result[b"Length"])
except (TypeError, KeyError, ValueError): except (TypeError, KeyError, ValueError) as e:
raise PdfFormatError( raise PdfFormatError(
"bad or missing Length in stream dict (%r)" "bad or missing Length in stream dict (%r)"
% result.get(b"Length", None) % result.get(b"Length", None)
) ) from e
stream_data = data[m.end() : m.end() + stream_len] stream_data = data[m.end() : m.end() + stream_len]
m = cls.re_stream_end.match(data, m.end() + stream_len) m = cls.re_stream_end.match(data, m.end() + stream_len)
check_format_condition(m, "stream end not found") check_format_condition(m, "stream end not found")