Commit 51696525 by olly Committed by kim-vde

Fix MP4 sniffing for very short files

The sniffer sniffs boxes at the start of the file to try and determine
whether the file is fragmented. However, if the file is extremely short
then it's possible that sniffing will try and read beyond the end of
the file, resulting i EOFException being thrown.

In general it's OK for sniffing to throw EOFException if the file is
not of the correct type. The problem in this case is that EOFException
can be thrown for an actual MP4 file, due to the sniffer continuing up
sniff atoms up to bytesToSearch in case the file is fragmented.

PiperOrigin-RevId: 325205389
parent 5de56cd6
...@@ -99,7 +99,12 @@ import java.io.IOException; ...@@ -99,7 +99,12 @@ import java.io.IOException;
// Read an atom header. // Read an atom header.
int headerSize = Atom.HEADER_SIZE; int headerSize = Atom.HEADER_SIZE;
buffer.reset(headerSize); buffer.reset(headerSize);
input.peekFully(buffer.getData(), 0, headerSize); boolean success =
input.peekFully(buffer.getData(), 0, headerSize, /* allowEndOfInput= */ true);
if (!success) {
// We've reached the end of the file.
break;
}
long atomSize = buffer.readUnsignedInt(); long atomSize = buffer.readUnsignedInt();
int atomType = buffer.readInt(); int atomType = buffer.readInt();
if (atomSize == Atom.DEFINES_LARGE_SIZE) { if (atomSize == Atom.DEFINES_LARGE_SIZE) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment