]> granicus.if.org Git - libass/commitdiff
Fix crash when event format spec is missing
authorGrigori Goronzy <goronzy@64pc31.informatik.uni-luebeck.de>
Thu, 2 Jul 2009 14:37:52 +0000 (16:37 +0200)
committerGrigori Goronzy <greg@blackbox>
Mon, 6 Jul 2009 23:39:07 +0000 (01:39 +0200)
libass didn't properly initialize its idea about the event format
specification (the Format: line in the [Events] section) in case none
was explicitly specified.  This ends in a crash due to access to a null
pointer.  It was changed so that the event format is initialized to
a reasonable default, the way it is also done for embedded subtitles.

libass/ass.c

index 7b90292e425ebe057e9d2a7b9714b283cd6c463f..5aef1447948bcc4afe80f731ee6e33eee39be06e 100644 (file)
@@ -560,6 +560,20 @@ static int process_info_line(ass_track_t *track, char *str)
     return 0;
 }
 
+static void event_format_fallback(ass_track_t *track)
+{
+    track->parser_priv->state = PST_EVENTS;
+    if (track->track_type == TRACK_TYPE_SSA)
+        track->event_format =
+            strdup
+            ("Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text");
+    else
+        track->event_format =
+            strdup
+            ("Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text");
+    ass_msg(MSGL_V, "No event format found, using fallback.\n");
+}
+
 static int process_events_line(ass_track_t *track, char *str)
 {
     if (!strncmp(str, "Format:", 7)) {
@@ -581,6 +595,10 @@ static int process_events_line(ass_track_t *track, char *str)
         eid = ass_alloc_event(track);
         event = track->events + eid;
 
+        // We can't parse events with event_format
+        if (!track->event_format)
+            event_format_fallback(track);
+
         process_event_tail(track, event, str, 0);
     } else {
         ass_msg(MSGL_V, "Not understood: %s  \n", str);
@@ -799,19 +817,10 @@ void ass_process_codec_private(ass_track_t *track, char *data, int size)
 {
     ass_process_data(track, data, size);
 
-    if (!track->event_format) {
-        // probably an mkv produced by ancient mkvtoolnix
-        // such files don't have [Events] and Format: headers
-        track->parser_priv->state = PST_EVENTS;
-        if (track->track_type == TRACK_TYPE_SSA)
-            track->event_format =
-                strdup
-                ("Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text");
-        else
-            track->event_format =
-                strdup
-                ("Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text");
-    }
+    // probably an mkv produced by ancient mkvtoolnix
+    // such files don't have [Events] and Format: headers
+    if (!track->event_format)
+        event_format_fallback(track);
 
     ass_process_force_style(track);
 }