[ 
https://issues.apache.org/jira/browse/PDFBOX-6357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18155045#comment-18155045
 ] 

Qiuye Wang commented on PDFBOX-6357:
------------------------------------

Thanks, Tilman. Yes, this would cover the case I reported. If the custom cache 
factory throws during initialization, Loader still owns the file and the 
{{finally}} block takes care of cleanup. On success, the file stays open for 
the returned {{PDDocument}}. I agree this is a narrow case. My report was based 
on source inspection.

> Loader.loadPDF should close a file it opened if a stream-cache factory throws
> -----------------------------------------------------------------------------
>
>                 Key: PDFBOX-6357
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6357
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 3.0.8 PDFBox
>            Reporter: Qiuye Wang
>            Priority: Minor
>
> Version reviewed: pdfbox 3.0.8
> The file overload opens a random-access source before parsing. Its failure 
> cleanup handles IOException. A user-supplied stream-cache factory can throw 
> an unchecked exception during document construction, before a PDDocument is 
> returned, leaving the file source without a matching close.
> Apply the same ownership rule when parsing exits with an unchecked exception. 
> This concerns files opened by the loader and a failing custom cache factory.
> https://github.com/apache/pdfbox/blob/9286e47d89d6877005c9d2d0f2fd38793a62519a/pdfbox/src/main/java/org/apache/pdfbox/Loader.java#L351-L366
> https://github.com/apache/pdfbox/blob/9286e47d89d6877005c9d2d0f2fd38793a62519a/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java#L140-L155
> Based on source inspection. This report was drafted with AI assistance.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to