question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CompoundDocument leaks a file descriptor

See original GitHub issue

The CompoundDocument class uses a LittleEndianRandomAccessFile internally to read the file contents: https://github.com/haraldk/TwelveMonkeys/blob/24c6682236e5a02151359486aa4075ddc5ab1534/common/common-io/src/main/java/com/twelvemonkeys/io/ole2/CompoundDocument.java#L105

However, input.close() is never called, which means that the underlying RandomAccessFile can hold an open file descriptor indefinitely in a long-running process.

Is there any reason not to just add a CompoundDocument#close() method?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tingleycommented, Aug 29, 2018

That seems to work. Tremendous, thanks for all your help!

1reaction
haraldkcommented, Sep 3, 2018

Thanks for following up on this!

That does indeed seem to be the case. Which is even worse…

My own code (the ThumbsDBImageReader) only uses the constructor taking an ImageInputStream parameter. And I believe this one is safe, as long as you close the ImageInputStream instance (which you can do externally).

Something like:

    private boolean isZipFileEncrypted(File file) throws IOException {
        // If you pass the File parameter to the CompoundDocument constructor it
        // opens a file pointer that is not released properly and remains open for
        // the entire lifetime of the application. Using an FileImageInputStream we take
        // control of the file pointer and release it properly after the check.
        try (ImageInputStream is = new FileImageInputStream(file)) {
            is.setByteOrder(ByteOrder.LITTLE_ENDIAN);
            new CompoundDocument(is);
            return true;
        } catch (CorruptDocumentException e) {
            return false;
        }
    }

This could perhaps work as a workaround for you, until I get the issue fixed.

Best regards,

– Harald K

Read more comments on GitHub >

github_iconTop Results From Across the Web

File descriptor leaks on Linux - java - Stack Overflow
I have an application which leaks thousands of file descriptors. lsof shows many opened regular files, but in memory dump of the application ......
Read more >
CWE-403: Exposure of File Descriptor to Unintended Control ...
While this issue is frequently called a file descriptor leak, the "leak" term is often used in two different ways - exposure of...
Read more >
Is there a way to track leaking file descriptors?
Click on Filesystem Activity track on the top;; Click on Filesystem Statistics popup menu on the toolbar of details below;; Select File Descriptor...
Read more >
VSMac leaks file descriptors which eventually leads to errors ...
When I tried to debug my app in the iOS simulator it showed an error message: "Could not register to wait for file...
Read more >
Help solving an elusive file descriptor leak
This was caused by having only 4096 inotify handlers. I've increased the limits and the issue is gone. fs.file-max = 131070 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found