You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Chris Cockayne (Jira)" <ji...@apache.org> on 2019/10/08 10:06:00 UTC

[jira] [Updated] (PDFBOX-4665) PDImageXObject createFromFileByExtension does not close FileInputStream in event of error

     [ https://issues.apache.org/jira/browse/PDFBOX-4665?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Chris Cockayne updated PDFBOX-4665:
-----------------------------------
    Component/s:     (was: Utilities)
                 PDModel

> PDImageXObject createFromFileByExtension does not close FileInputStream in event of error
> -----------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-4665
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4665
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.17
>            Reporter: Chris Cockayne
>            Priority: Minor
>
> if you pass a mislabelled jpeg image file to PDImageXObject.createFromFileByExtension, e.g. a png image that is incorrectly named foo.jpg, then the file is treated as a JPEG. A FileInputStream is opened and JPEGFactory.createFromStream then (correctly) throws an IIOException. However, the FileInputStream is not closed.
> Suggested change:
> *old*
> if ("jpg".equals(ext) || "jpeg".equals(ext))
>  {
>  FileInputStream fis = new FileInputStream(file);
>  PDImageXObject imageXObject = JPEGFactory.createFromStream(doc, fis);
>  fis.close();
>  return imageXObject;
>  }
> *new*
> if ("jpg".equals(ext) || "jpeg".equals(ext))
>  {
>  FileInputStream fis = null;
>  try {
>  fis = new FileInputStream(file);
>  PDImageXObject imageXObject = JPEGFactory.createFromStream(doc, fis);
>  return imageXObject;
>  } finally {
>  IOUtils.closeQuietly(fis);
>  }
>  }



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org