Commit bf3d6028 by olly Committed by Oliver Woodman

Make SsaDecoder more robust against malformed content

Issue: #3645

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=180559196
parent 0821f578
...@@ -150,6 +150,12 @@ public final class SsaDecoder extends SimpleSubtitleDecoder { ...@@ -150,6 +150,12 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
break; break;
} }
} }
if (formatStartIndex == C.INDEX_UNSET
|| formatEndIndex == C.INDEX_UNSET
|| formatTextIndex == C.INDEX_UNSET) {
// Set to 0 so that parseDialogueLine skips lines until a complete format line is found.
formatKeyCount = 0;
}
} }
/** /**
...@@ -161,12 +167,17 @@ public final class SsaDecoder extends SimpleSubtitleDecoder { ...@@ -161,12 +167,17 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
*/ */
private void parseDialogueLine(String dialogueLine, List<Cue> cues, LongArray cueTimesUs) { private void parseDialogueLine(String dialogueLine, List<Cue> cues, LongArray cueTimesUs) {
if (formatKeyCount == 0) { if (formatKeyCount == 0) {
Log.w(TAG, "Skipping dialogue line before format: " + dialogueLine); Log.w(TAG, "Skipping dialogue line before complete format: " + dialogueLine);
return; return;
} }
String[] lineValues = dialogueLine.substring(DIALOGUE_LINE_PREFIX.length()) String[] lineValues = dialogueLine.substring(DIALOGUE_LINE_PREFIX.length())
.split(",", formatKeyCount); .split(",", formatKeyCount);
if (lineValues.length != formatKeyCount) {
Log.w(TAG, "Skipping dialogue line with fewer columns than format: " + dialogueLine);
return;
}
long startTimeUs = SsaDecoder.parseTimecodeUs(lineValues[formatStartIndex]); long startTimeUs = SsaDecoder.parseTimecodeUs(lineValues[formatStartIndex]);
if (startTimeUs == C.TIME_UNSET) { if (startTimeUs == C.TIME_UNSET) {
Log.w(TAG, "Skipping invalid timing: " + dialogueLine); Log.w(TAG, "Skipping invalid timing: " + dialogueLine);
......
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