From eeb73a86ea21d07c59ac010ce499517f000ca76f Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Thu, 10 Sep 2015 18:30:47 +0100 Subject: [PATCH] Improve sniffer behavior for fragmented MP4. - Allow a moof box to exceed the search size. - Return immediately after reading an ftyp box with no compatible types. Issue: #784 --- .../android/exoplayer/extractor/mp4/Sniffer.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Sniffer.java b/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Sniffer.java index ece82e5beb..96878b82d9 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Sniffer.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Sniffer.java @@ -102,13 +102,9 @@ import java.io.IOException; atomSize = buffer.readLong(); } // Check the atom size is large enough to include its header. - if (atomSize < headerSize || atomSize > Integer.MAX_VALUE) { + if (atomSize < headerSize) { return false; } - // Stop searching if reading this atom would exceed the search limit. - if (bytesSearched + atomSize > bytesToSearch) { - break; - } int atomDataSize = (int) atomSize - headerSize; if (atomType == Atom.TYPE_ftyp) { if (atomDataSize < 8) { @@ -126,10 +122,18 @@ import java.io.IOException; break; } } + // There is only one ftyp box, so reject the file if the file type in this box was invalid. + if (!foundGoodFileType) { + return false; + } } else if (atomType == Atom.TYPE_moof) { foundFragment = true; break; } else if (atomDataSize != 0) { + // Stop searching if reading this atom would exceed the search limit. + if (bytesSearched + atomSize >= bytesToSearch) { + break; + } input.advancePeekPosition(atomDataSize); } bytesSearched += atomSize;