You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tika.apache.org by "Wladimir Leite (Jira)" <ji...@apache.org> on 2021/05/14 20:54:00 UTC

[jira] [Created] (TIKA-3405) Open file leak in MP4Parser

Wladimir Leite created TIKA-3405:
------------------------------------

             Summary: Open file leak in MP4Parser
                 Key: TIKA-3405
                 URL: https://issues.apache.org/jira/browse/TIKA-3405
             Project: Tika
          Issue Type: Bug
          Components: parser
    Affects Versions: 1.26
         Environment: Windows 10, Oracle JDK 8 (64-bit, 1.8.0_281)
            Reporter: Wladimir Leite
         Attachments: 1.mov

After upgrading Tika to version 1.26 (I was using 1.20 before), I started to have some trouble with open video files that after Tika parsing couldn't be moved/deleted because they remain opened after finishing parsing process.

Investigating the issue, which happens with MOV/QT video files (not all of them), I found out that it happens whenever an exception is throw inside {{IsoFile()}} constructor (which is in fact part of MP4Parser project). 

A simple test snippet to reproduce the issue:
{code:java}
File file = ...; //A test file
try (IsoFile isoFile = new IsoFile(file)) {
    System.out.println("isoFile = " + isoFile);
} catch (Exception e) {
    e.printStackTrace();
}
//Here the file is still opened
{code}
Here is the relevant part of {{IsoFile}} constructor: 

 
{code:java}
public IsoFile(File file) throws IOException {
    this(new FileInputStream(file).getChannel(), new PropertyBoxParserImpl());
}
public IsoFile(ReadableByteChannel readableByteChannel, BoxParser boxParser) throws    IOException {
    this.readableByteChannel = readableByteChannel;
    initContainer(readableByteChannel, -1, boxParser);
}
{code}
So if {{initContainer()}} fails {{readableByteChannel}} will not be closed.
In the case of the videos I have here, {{initContainer()}} throws a {{RuntimeException}} because an unsupported data (although  the videos are valid and I can open them):
{code:java}
java.lang.RuntimeException: box size of zero means 'till end of file. That is not yet supported{code}

A possible solution would be changing {{IsoFile}} constructor:
{code:java}
public IsoFile(ReadableByteChannel readableByteChannel, BoxParser boxParser) throws IOException {
    this.readableByteChannel = readableByteChannel;
    try {
        initContainer(readableByteChannel, -1, boxParser);
    } catch (Exception e) {
        try {
            close();
        } catch (Exception e2) {
        }
        throw e;
    }
}{code}
A sample file that cause this issue is attached. I have others if necessary.

 



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