Commit 6b03e6a1 by Oliver Woodman

Fix MP4+MKV sniffing to handle empty atoms / EBML elements.

Issue: #641
parent 648f224d
...@@ -102,7 +102,7 @@ import java.io.IOException; ...@@ -102,7 +102,7 @@ import java.io.IOException;
atomSize = buffer.readLong(); atomSize = buffer.readLong();
} }
// Check the atom size is large enough to include its header. // 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; return false;
} }
// Stop searching if reading this atom would exceed the search limit. // Stop searching if reading this atom would exceed the search limit.
...@@ -129,7 +129,7 @@ import java.io.IOException; ...@@ -129,7 +129,7 @@ import java.io.IOException;
} else if (atomType == Atom.TYPE_moof) { } else if (atomType == Atom.TYPE_moof) {
foundFragment = true; foundFragment = true;
break; break;
} else { } else if (atomDataSize != 0) {
input.advancePeekPosition(atomDataSize); input.advancePeekPosition(atomDataSize);
} }
bytesSearched += atomSize; bytesSearched += atomSize;
......
...@@ -76,12 +76,14 @@ import java.io.IOException; ...@@ -76,12 +76,14 @@ import java.io.IOException;
return false; return false;
} }
long size = readUint(input); long size = readUint(input);
if (size <= 0 || size > Integer.MAX_VALUE) { if (size < 0 || size > Integer.MAX_VALUE) {
return false; return false;
} }
if (size != 0) {
input.advancePeekPosition((int) size); input.advancePeekPosition((int) size);
peekLength += size; peekLength += size;
} }
}
return peekLength == headerStart + headerSize; return peekLength == headerStart + headerSize;
} }
......
...@@ -1187,7 +1187,8 @@ public final class WebmExtractor implements Extractor { ...@@ -1187,7 +1187,8 @@ public final class WebmExtractor implements Extractor {
System.arraycopy(NalUnitUtil.NAL_START_CODE, 0, buffer, bufferPosition, System.arraycopy(NalUnitUtil.NAL_START_CODE, 0, buffer, bufferPosition,
NalUnitUtil.NAL_START_CODE.length); NalUnitUtil.NAL_START_CODE.length);
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; bufferPosition += nalUnitLength;
parent.skipBytes(nalUnitLength); parent.skipBytes(nalUnitLength);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment