Skip to content

Commit

Permalink
Fix MP4+MKV sniffing to handle empty atoms / EBML elements.
Browse files Browse the repository at this point in the history
Issue: google#641
  • Loading branch information
ojw28 committed Jul 22, 2015
1 parent 648f224 commit 6b03e6a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static boolean sniffInternal(ExtractorInput input, int searchLength, boo
atomSize = buffer.readLong();
}
// Check the atom size is large enough to include its header.
if (atomSize <= headerSize || atomSize > Integer.MAX_VALUE) {
if (atomSize < headerSize || atomSize > Integer.MAX_VALUE) {
return false;
}
// Stop searching if reading this atom would exceed the search limit.
Expand All @@ -129,7 +129,7 @@ private static boolean sniffInternal(ExtractorInput input, int searchLength, boo
} else if (atomType == Atom.TYPE_moof) {
foundFragment = true;
break;
} else {
} else if (atomDataSize != 0) {
input.advancePeekPosition(atomDataSize);
}
bytesSearched += atomSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ public boolean sniff(ExtractorInput input) throws IOException, InterruptedExcept
return false;
}
long size = readUint(input);
if (size <= 0 || size > Integer.MAX_VALUE) {
if (size < 0 || size > Integer.MAX_VALUE) {
return false;
}
input.advancePeekPosition((int) size);
peekLength += size;
if (size != 0) {
input.advancePeekPosition((int) size);
peekLength += size;
}
}
return peekLength == headerStart + headerSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,8 @@ private static Pair<List<byte[]>, Integer> parseHEVCCodecPrivate(ParsableByteArr
System.arraycopy(NalUnitUtil.NAL_START_CODE, 0, buffer, bufferPosition,
NalUnitUtil.NAL_START_CODE.length);
bufferPosition += NalUnitUtil.NAL_START_CODE.length;
System.arraycopy(parent.data, parent.getPosition(), buffer, bufferPosition, nalUnitLength);
System.arraycopy(parent.data, parent.getPosition(), buffer, bufferPosition,
nalUnitLength);
bufferPosition += nalUnitLength;
parent.skipBytes(nalUnitLength);
}
Expand Down

0 comments on commit 6b03e6a

Please sign in to comment.