Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-4665

PDImageXObject createFromFileByExtension does not close FileInputStream in event of error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0.17
    • 2.0.18
    • PDModel
    • None

    Description

      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.

      I saw that this is fixed in 3.0.0-SNAPSHOT:

      if ("jpg".equals(ext) || "jpeg".equals(ext))
      {
      try (FileInputStream fis = new FileInputStream(file))
      { return JPEGFactory.createFromStream(doc, fis); }

      }

       

      but if another 2.0.x release is made it would be good to include this.

       

      Attachments

        Activity

          People

            tilman Tilman Hausherr
            cco8314 Chris Cockayne
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: