Fix HLS ID3 sniffing

The input.getLength() check is invalid because the length may be
unknown (i.e. if the server doesn't include a Content-Length
response header when serving chunks).

Issue: #5063 (tangentially related only)

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=222406347
This commit is contained in:
olly 2018-11-21 07:38:37 -08:00 committed by Oliver Woodman
parent 5f12b065a4
commit dd47bfffb0

View File

@ -32,6 +32,7 @@ import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.util.ParsableByteArray;
import com.google.android.exoplayer2.util.TimestampAdjuster;
import com.google.android.exoplayer2.util.Util;
import java.io.EOFException;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@ -312,8 +313,10 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
private long peekId3PrivTimestamp(ExtractorInput input) throws IOException, InterruptedException {
input.resetPeekPosition();
if (input.getLength() < Id3Decoder.ID3_HEADER_LENGTH
|| !input.peekFully(id3Data.data, 0, Id3Decoder.ID3_HEADER_LENGTH, true)) {
try {
input.peekFully(id3Data.data, 0, Id3Decoder.ID3_HEADER_LENGTH);
} catch (EOFException e) {
// The input isn't long enough for there to be any ID3 data.
return C.TIME_UNSET;
}
id3Data.reset(Id3Decoder.ID3_HEADER_LENGTH);
@ -329,9 +332,7 @@ import java.util.concurrent.atomic.AtomicInteger;
id3Data.reset(requiredCapacity);
System.arraycopy(data, 0, id3Data.data, 0, Id3Decoder.ID3_HEADER_LENGTH);
}
if (!input.peekFully(id3Data.data, Id3Decoder.ID3_HEADER_LENGTH, id3Size, true)) {
return C.TIME_UNSET;
}
input.peekFully(id3Data.data, Id3Decoder.ID3_HEADER_LENGTH, id3Size);
Metadata metadata = id3Decoder.decode(id3Data.data, id3Size);
if (metadata == null) {
return C.TIME_UNSET;