diff mbox series

[FFmpeg-devel] libavformat/lrcdec: Fix count of timestamp

Message ID 53faacb3ea922fde5ca94f6f1da537f030bee916.1583593011.git.gang.zhao.42@gmail.com
State New
Headers show
Series [FFmpeg-devel] libavformat/lrcdec: Fix count of timestamp
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Zhao, Gang March 7, 2020, 3:12 p.m. UTC
Current function count_ts will count invalid timestamp formats like
[00:00:00] [00-00-00] or [00:00.00][[[00:00.00]]] as valid timestamp.
This could cause some subtitles would be incorrectly counted as
timestamp. Fix it by using function read_ts to check valid timestamp
and get the offset.

Fixes trac #7255.

Signed-off-by: Zhao, Gang <gang.zhao.42@gmail.com>
---
 libavformat/lrcdec.c | 38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)
diff mbox series

Patch

diff --git libavformat/lrcdec.c libavformat/lrcdec.c
index a9a117691a..3b206cf079 100644
--- libavformat/lrcdec.c
+++ libavformat/lrcdec.c
@@ -49,31 +49,6 @@  static int64_t find_header(const char *p)
     }
 }
 
-static int64_t count_ts(const char *p)
-{
-    int64_t offset = 0;
-    int in_brackets = 0;
-
-    for(;;) {
-        if(p[offset] == ' ' || p[offset] == '\t') {
-            offset++;
-        } else if(p[offset] == '[') {
-            offset++;
-            in_brackets++;
-        } else if (p[offset] == ']' && in_brackets) {
-            offset++;
-            in_brackets--;
-        } else if(in_brackets &&
-                 (p[offset] == ':' || p[offset] == '.' || p[offset] == '-' ||
-                 (p[offset] >= '0' && p[offset] <= '9'))) {
-            offset++;
-        } else {
-            break;
-        }
-    }
-    return offset;
-}
-
 static int64_t read_ts(const char *p, int64_t *start)
 {
     int64_t offset = 0;
@@ -99,6 +74,19 @@  static int64_t read_ts(const char *p, int64_t *start)
     return offset;
 }
 
+static int64_t count_ts(const char *p)
+{
+    int64_t total_offset = 0;
+    int64_t offset, start;
+
+    while ((offset = read_ts(p, &start)) != 0) {
+        total_offset += offset;
+        p += offset;
+    }
+
+    return total_offset;
+}
+
 static int64_t read_line(AVBPrint *buf, AVIOContext *pb)
 {
     int64_t pos = avio_tell(pb);