Skip to content

Commit 64f6d4e

Browse files
radarherehugovk
andauthored
Close PdfParser if error occurs during init (#9539)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent a865345 commit 64f6d4e

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/PIL/PdfParser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,11 @@ def __init__(
402402
self.pages_ref: IndirectReference | None
403403
self.last_xref_section_offset: int | None
404404
if self.buf:
405-
self.read_pdf_info()
405+
try:
406+
self.read_pdf_info()
407+
except PdfFormatError:
408+
self.close()
409+
raise
406410
else:
407411
self.file_size_total = self.file_size_this = 0
408412
self.root = PdfDict()

0 commit comments

Comments
 (0)