mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Increase search size in mp4 sniffing once moov has been found
Issue:#5320 PiperOrigin-RevId: 228142567
This commit is contained in:
parent
e8a7cb2546
commit
147deafd01
1 changed files with 15 additions and 6 deletions
|
|
@ -27,9 +27,7 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
/* package */ final class Sniffer {
|
/* 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 SEARCH_LENGTH = 4 * 1024;
|
||||||
|
|
||||||
private static final int[] COMPATIBLE_BRANDS = new int[] {
|
private static final int[] COMPATIBLE_BRANDS = new int[] {
|
||||||
|
|
@ -112,12 +110,16 @@ import java.io.IOException;
|
||||||
atomSize = buffer.readLong();
|
atomSize = buffer.readLong();
|
||||||
} else if (atomSize == Atom.EXTENDS_TO_END_SIZE) {
|
} else if (atomSize == Atom.EXTENDS_TO_END_SIZE) {
|
||||||
// The atom extends to the end of the file.
|
// The atom extends to the end of the file.
|
||||||
long endPosition = input.getLength();
|
long fileEndPosition = input.getLength();
|
||||||
if (endPosition != C.LENGTH_UNSET) {
|
if (fileEndPosition != C.LENGTH_UNSET) {
|
||||||
atomSize = endPosition - input.getPeekPosition() + headerSize;
|
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) {
|
if (atomSize < headerSize) {
|
||||||
// The file is invalid because the atom size is too small for its header.
|
// The file is invalid because the atom size is too small for its header.
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -125,6 +127,13 @@ import java.io.IOException;
|
||||||
bytesSearched += headerSize;
|
bytesSearched += headerSize;
|
||||||
|
|
||||||
if (atomType == Atom.TYPE_moov) {
|
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.
|
// Check for an mvex atom inside the moov atom to identify whether the file is fragmented.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue