Skip to content

XGC-150: ImageLoaderRawPNG closes its stream once PNGFile has read it - #34

Open
plutext wants to merge 1 commit into
apache:mainfrom
plutext:XGC-150
Open

plutext wants to merge 1 commit into
apache:mainfrom
plutext:XGC-150

Conversation

@plutext

@plutext plutext commented Oct 11, 2026

Copy link
Copy Markdown

Fixes XGC-150.

ImageLoaderRawPNG.loadImage() takes the ImageInputStream out of the session's Source (XmlSourceUtil.removeStreams) and never closes it. PNGFile's constructor already reads every chunk it keeps into memory, and getImageRawPNG() serves the image data from those byte arrays, so the stream isn't needed once PNGFile is built.

Left open, the PNG's file stays open until garbage collection, together with ImageIO's imageio*.tmp cache file where the source came from an InputStream. On Windows neither can be deleted after rendering (seen from docx4j, plutext/docx4j#609).

The stream is now closed in a finally, and the stale comment is gone. ImageLoaderRawPNGTestCase.testLoadImageClosesStream fails without the change; the full test suite passes and checkstyle is clean.

loadImage took the ImageInputStream out of the Source and never closed
it, although PNGFile reads every chunk it keeps into memory in its
constructor.  The image's file stayed open until garbage collection,
with ImageIO's cache file beside it, so on Windows neither could be
deleted after rendering.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant