Skip to content

Commit

Permalink
Make SsaDecoder more robust against malformed content
Browse files Browse the repository at this point in the history
Issue: google#3645

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=180559196
  • Loading branch information
ojw28 committed Jan 3, 2018
1 parent ad95a14 commit f657893
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ private void parseFormatLine(String formatLine) {
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;
}
}

/**
Expand All @@ -161,12 +167,17 @@ private void parseFormatLine(String formatLine) {
*/
private void parseDialogueLine(String dialogueLine, List<Cue> cues, LongArray cueTimesUs) {
if (formatKeyCount == 0) {
Log.w(TAG, "Skipping dialogue line before format: " + dialogueLine);
Log.w(TAG, "Skipping dialogue line before complete format: " + dialogueLine);
return;
}

String[] lineValues = dialogueLine.substring(DIALOGUE_LINE_PREFIX.length())
.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]);
if (startTimeUs == C.TIME_UNSET) {
Log.w(TAG, "Skipping invalid timing: " + dialogueLine);
Expand Down

0 comments on commit f657893

Please sign in to comment.