Commit 32bad691 by aquilescanta Committed by Oliver Woodman

Increase search size in mp4 sniffing once moov has been found

Issue:#5320
PiperOrigin-RevId: 228142567
parent ff9a40f0
......@@ -27,9 +27,7 @@ import java.io.IOException;
*/
/* package */ final class Sniffer {
/**
* The maximum number of bytes to peek when sniffing.
*/
/** The maximum number of bytes to peek when sniffing. */
private static final int SEARCH_LENGTH = 4 * 1024;
private static final int[] COMPATIBLE_BRANDS = new int[] {
......@@ -112,12 +110,16 @@ import java.io.IOException;
atomSize = buffer.readLong();
} else if (atomSize == Atom.EXTENDS_TO_END_SIZE) {
// The atom extends to the end of the file.
long endPosition = input.getLength();
if (endPosition != C.LENGTH_UNSET) {
atomSize = endPosition - input.getPeekPosition() + headerSize;
long fileEndPosition = input.getLength();
if (fileEndPosition != C.LENGTH_UNSET) {
atomSize = fileEndPosition - input.getPeekPosition() + headerSize;
}
}
if (inputLength != C.LENGTH_UNSET && bytesSearched + atomSize > inputLength) {
// The file is invalid because the atom extends past the end of the file.
return false;
}
if (atomSize < headerSize) {
// The file is invalid because the atom size is too small for its header.
return false;
......@@ -125,6 +127,13 @@ import java.io.IOException;
bytesSearched += headerSize;
if (atomType == Atom.TYPE_moov) {
// We have seen the moov atom. We increase the search size to make sure we don't miss an
// mvex atom because the moov's size exceeds the search length.
bytesToSearch += (int) atomSize;
if (inputLength != C.LENGTH_UNSET && bytesToSearch > inputLength) {
// Make sure we don't exceed the file size.
bytesToSearch = (int) inputLength;
}
// Check for an mvex atom inside the moov atom to identify whether the file is fragmented.
continue;
}
......
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