Uploaded image for project: 'Batik'
  1. Batik
  2. BATIK-895

DeflaterOutputStream not closed, causes OutOfMemoryError

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Resolution: Unresolved
    • Affects Version/s: 1.7
    • Fix Version/s: None
    • Component/s: SVGGraphics2D
    • Labels:
      None
    • Environment:
      Operating System: Windows XP
      Platform: PC

      Description

      The close() method should be called on java.util.zip.DeflaterOutputStream instances when they are no longer needed. In particular, the writeIDAT() and writeZTXT() methods in org.apache.batik.ext.awt.image.codec.png.PNGImageEncoder do not call close() on DeflaterOutputStream.

      Since close() is not called, end() is not called on the java.util.zip.Deflater instance until it is garbage collected. Due to the implementation of Deflater, this causes an OutOfMemoryError to occur in some cases when the PNGImageEncoder is invoked repeatedly. This issue with Deflater is described in detail at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4797189, where the recommended solution is to ensure that end() is called on the Deflater in a timely fashion.

      Tested in Batik versions 1.5 and 1.7.

      Stack trace:
      [...]
      Caused by: java.lang.OutOfMemoryError
      at java.util.zip.Deflater.init(Native Method)
      at java.util.zip.Deflater.<init>(Deflater.java:134)
      at java.util.zip.Deflater.<init>(Deflater.java:143)
      at org.apache.batik.ext.awt.image.codec.PNGImageEncoder.writeIDAT(Unknown Source)
      at org.apache.batik.ext.awt.image.codec.PNGImageEncoder.encode(Unknown Source)
      at org.apache.batik.svggen.ImageHandlerBase64Encoder.encodeImage(Unknown Source)
      at org.apache.batik.svggen.ImageHandlerBase64Encoder.handleHREF(Unknown Source)
      at org.apache.batik.svggen.ImageHandlerBase64Encoder.handleHREF(Unknown Source)
      at org.apache.batik.svggen.DefaultImageHandler.handleImage(Unknown Source)
      at org.apache.batik.svggen.SimpleImageHandler.handleImage(Unknown Source)
      at org.apache.batik.svggen.SVGGraphics2D.drawImage(Unknown Source)
      at org.apache.batik.svggen.SVGGraphics2D.drawImage(Unknown Source)
      [...]

        Attachments

          Activity

            People

            • Assignee:
              batik-dev@xmlgraphics.apache.org Batik Developer's Mailing list
              Reporter:
              liamsb@ca.ibm.com liamsb
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: