From d075e4f91b2597e3608d6ae911a4eb34359e873b Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 21 Nov 2018 07:38:37 -0800 Subject: [PATCH] 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 --- .../android/exoplayer2/source/hls/HlsMediaChunk.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaChunk.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaChunk.java index 0cfe31f3b9..20134e9efc 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaChunk.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaChunk.java @@ -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; @@ -313,8 +314,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); @@ -330,9 +333,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;