You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tika.apache.org by "Luís Filipe Nassif (Jira)" <ji...@apache.org> on 2021/05/17 13:51:00 UTC
[jira] [Commented] (TIKA-3405) Open file leak in MP4Parser
[ https://issues.apache.org/jira/browse/TIKA-3405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17346176#comment-17346176 ]
Luís Filipe Nassif commented on TIKA-3405:
------------------------------------------
Seems there is a previous issue related to this: https://issues.apache.org/jira/browse/TIKA-3128
And a PR was already proposed to fix the issue: [https://github.com/tballison/mp4parser/pull/1]
I prefer [~tc-wleite]'s solution instead of hiding the RuntimeException.
> 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
> Priority: Major
> Attachments: 1.mov
>
>
> After upgrading Tika to version 1.26 (I was using 1.20 before), I started to have some trouble with video files that after Tika parsing couldn't be moved/deleted because they remained opened after finishing parsing process.
> Investigating the issue, which in my case affects 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)