Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parts of Ogg can not be played #7608

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public boolean populate(ExtractorInput input) throws IOException {
if ((pageHeader.type & 0x01) == 0x01 && packetArray.limit() == 0) {
// After seeking, the first packet may be the remainder
// part of a continued packet which has to be discarded.
bytesToSkip += calculatePacketSize(segmentIndex);
bytesToSkip += calculatePacketSize(segmentIndex, input);
segmentIndex += segmentCount;
}
input.skipFully(bytesToSkip);
currentSegmentIndex = segmentIndex;
}

int size = calculatePacketSize(currentSegmentIndex);
int size = calculatePacketSize(currentSegmentIndex, input);
int segmentIndex = currentSegmentIndex + segmentCount;
if (size > 0) {
if (packetArray.capacity() < packetArray.limit() + size) {
Expand Down Expand Up @@ -137,7 +137,7 @@ public void trimPayload() {
* @param startSegmentIndex the index of the first segment of the packet.
* @return Size of the packet.
*/
private int calculatePacketSize(int startSegmentIndex) {
private int calculatePacketSize(int startSegmentIndex, ExtractorInput input) {
segmentCount = 0;
int size = 0;
while (startSegmentIndex + segmentCount < pageHeader.pageSegmentCount) {
Expand All @@ -148,6 +148,11 @@ private int calculatePacketSize(int startSegmentIndex) {
break;
}
}

if (OggReadCheckUtil.checkReadLengthValidity(input, size)) {
size = OggReadCheckUtil.fixFileReadLength(input);
}

return size;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ public boolean populate(ExtractorInput input, boolean quiet) throws IOException
bodySize += laces[i];
}

if (OggReadCheckUtil.checkReadLengthValidity(input, bodySize)) {
bodySize = OggReadCheckUtil.fixFileReadLength(input);
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.google.android.exoplayer2.extractor.ogg;

import com.google.android.exoplayer2.extractor.ExtractorInput;

/**
* Ogg File read verification tool
*/
class OggReadCheckUtil {

/**
* Verify that the length of the read exceeds the file length
* @param input {@link ExtractorInput}
* @param readLength read length
* @return true The read length is greater than the file length
*/
public static boolean checkReadLengthValidity(ExtractorInput input, int readLength) {
return input.getPeekPosition() + readLength > input.getLength() ;
}

/**
* Fix read length
* @param input {@link ExtractorInput}
* @return Length of read after fixed
*/
public static int fixFileReadLength(ExtractorInput input) {
return (int) (input.getLength() - input.getPeekPosition());
}
}