diff --git a/libavformat/assdec.c b/libavformat/assdec.c
index ba7bc8b787c581d4b1bb7b337040a26c9f317ff3..87ce2f25eee673c78029f35cf2e0f05d5e4c773a 100644
--- a/libavformat/assdec.c
+++ b/libavformat/assdec.c
@@ -57,14 +57,14 @@ static int ass_read_close(AVFormatContext *s)
 static int read_dialogue(ASSContext *ass, AVBPrint *dst, const uint8_t *p,
                          int64_t *start, int *duration)
 {
-    int pos;
+    int pos = 0;
     int64_t end;
     int hh1, mm1, ss1, ms1;
     int hh2, mm2, ss2, ms2;
 
     if (sscanf(p, "Dialogue: %*[^,],%d:%d:%d%*c%d,%d:%d:%d%*c%d,%n",
                &hh1, &mm1, &ss1, &ms1,
-               &hh2, &mm2, &ss2, &ms2, &pos) >= 8) {
+               &hh2, &mm2, &ss2, &ms2, &pos) >= 8 && pos > 0) {
 
         /* This is not part of the sscanf itself in order to handle an actual
          * number (which would be the Layer) or the form "Marked=N" (which is