Commit c59fc475 by Oliver Woodman

Throw ParserException from parsers when a parse exception occurs.

parent 13aaa5a5
...@@ -22,6 +22,10 @@ import java.io.IOException; ...@@ -22,6 +22,10 @@ import java.io.IOException;
*/ */
public class ParserException extends IOException { public class ParserException extends IOException {
public ParserException() {
super();
}
public ParserException(String message) { public ParserException(String message) {
super(message); super(message);
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer.extractor.webm; package com.google.android.exoplayer.extractor.webm;
import com.google.android.exoplayer.C; import com.google.android.exoplayer.C;
import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.extractor.ExtractorInput; import com.google.android.exoplayer.extractor.ExtractorInput;
import com.google.android.exoplayer.util.Assertions; import com.google.android.exoplayer.util.Assertions;
...@@ -100,7 +101,7 @@ import java.util.Stack; ...@@ -100,7 +101,7 @@ import java.util.Stack;
return true; return true;
case TYPE_UNSIGNED_INT: case TYPE_UNSIGNED_INT:
if (elementContentSize > MAX_INTEGER_ELEMENT_SIZE_BYTES) { if (elementContentSize > MAX_INTEGER_ELEMENT_SIZE_BYTES) {
throw new IllegalStateException("Invalid integer size: " + elementContentSize); throw new ParserException("Invalid integer size: " + elementContentSize);
} }
output.integerElement(elementId, readInteger(input, (int) elementContentSize)); output.integerElement(elementId, readInteger(input, (int) elementContentSize));
elementState = ELEMENT_STATE_READ_ID; elementState = ELEMENT_STATE_READ_ID;
...@@ -108,14 +109,14 @@ import java.util.Stack; ...@@ -108,14 +109,14 @@ import java.util.Stack;
case TYPE_FLOAT: case TYPE_FLOAT:
if (elementContentSize != VALID_FLOAT32_ELEMENT_SIZE_BYTES if (elementContentSize != VALID_FLOAT32_ELEMENT_SIZE_BYTES
&& elementContentSize != VALID_FLOAT64_ELEMENT_SIZE_BYTES) { && elementContentSize != VALID_FLOAT64_ELEMENT_SIZE_BYTES) {
throw new IllegalStateException("Invalid float size: " + elementContentSize); throw new ParserException("Invalid float size: " + elementContentSize);
} }
output.floatElement(elementId, readFloat(input, (int) elementContentSize)); output.floatElement(elementId, readFloat(input, (int) elementContentSize));
elementState = ELEMENT_STATE_READ_ID; elementState = ELEMENT_STATE_READ_ID;
return true; return true;
case TYPE_STRING: case TYPE_STRING:
if (elementContentSize > Integer.MAX_VALUE) { if (elementContentSize > Integer.MAX_VALUE) {
throw new IllegalStateException("String element size: " + elementContentSize); throw new ParserException("String element size: " + elementContentSize);
} }
output.stringElement(elementId, readString(input, (int) elementContentSize)); output.stringElement(elementId, readString(input, (int) elementContentSize));
elementState = ELEMENT_STATE_READ_ID; elementState = ELEMENT_STATE_READ_ID;
...@@ -129,7 +130,7 @@ import java.util.Stack; ...@@ -129,7 +130,7 @@ import java.util.Stack;
elementState = ELEMENT_STATE_READ_ID; elementState = ELEMENT_STATE_READ_ID;
break; break;
default: default:
throw new IllegalStateException("Invalid element type " + type); throw new ParserException("Invalid element type " + type);
} }
} }
} }
......
...@@ -26,7 +26,6 @@ import com.google.android.exoplayer.extractor.ExtractorOutput; ...@@ -26,7 +26,6 @@ import com.google.android.exoplayer.extractor.ExtractorOutput;
import com.google.android.exoplayer.extractor.PositionHolder; import com.google.android.exoplayer.extractor.PositionHolder;
import com.google.android.exoplayer.extractor.SeekMap; import com.google.android.exoplayer.extractor.SeekMap;
import com.google.android.exoplayer.extractor.TrackOutput; import com.google.android.exoplayer.extractor.TrackOutput;
import com.google.android.exoplayer.util.Assertions;
import com.google.android.exoplayer.util.LongArray; import com.google.android.exoplayer.util.LongArray;
import com.google.android.exoplayer.util.MimeTypes; import com.google.android.exoplayer.util.MimeTypes;
import com.google.android.exoplayer.util.NalUnitUtil; import com.google.android.exoplayer.util.NalUnitUtil;
...@@ -738,7 +737,7 @@ public final class WebmExtractor implements Extractor { ...@@ -738,7 +737,7 @@ public final class WebmExtractor implements Extractor {
contentSize - blockTrackNumberLength - headerSize - totalSamplesSize; contentSize - blockTrackNumberLength - headerSize - totalSamplesSize;
} else { } else {
// Lacing is always in the range 0--3. // Lacing is always in the range 0--3.
throw new IllegalStateException("Unexpected lacing value: " + lacing); throw new ParserException("Unexpected lacing value: " + lacing);
} }
} }
...@@ -1257,7 +1256,9 @@ public final class WebmExtractor implements Extractor { ...@@ -1257,7 +1256,9 @@ public final class WebmExtractor implements Extractor {
// TODO: Deduplicate with AtomParsers.parseAvcCFromParent. // TODO: Deduplicate with AtomParsers.parseAvcCFromParent.
buffer.setPosition(4); buffer.setPosition(4);
int nalUnitLengthFieldLength = (buffer.readUnsignedByte() & 0x03) + 1; int nalUnitLengthFieldLength = (buffer.readUnsignedByte() & 0x03) + 1;
Assertions.checkState(nalUnitLengthFieldLength != 3); if (nalUnitLengthFieldLength == 3) {
throw new ParserException();
}
List<byte[]> initializationData = new ArrayList<>(); List<byte[]> initializationData = new ArrayList<>();
int numSequenceParameterSets = buffer.readUnsignedByte() & 0x1F; int numSequenceParameterSets = buffer.readUnsignedByte() & 0x1F;
for (int i = 0; i < numSequenceParameterSets; i++) { for (int i = 0; i < numSequenceParameterSets; i++) {
......
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