[FFmpeg-devel] [PATCH] wtvdec: return error when filetime_to_iso8601/crazytime_to_iso8601 conversion fails

Peter Ross pross at xvid.org
Mon Jul 2 02:28:31 CEST 2012


---

Okay, lets address the root cause here.

When gmtime() fails within {filetime,crazytime}_to_iso8601 is should return an error value,
and instruct the callee to disregard the metadata entry. gmtime errors are very very possible
here given the difference between wtv/win32 and unix epochs.

This style of error handling was done previously for oledate_to_iso8601, but not for
filetime/crazytime. The patch below makes it consistent.

Alexander/Michael: I wont have computer access for some time, so apply or rework how you see fit.


 libavformat/wtvdec.c |   32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
index 338eff8..eb31250 100644
--- a/libavformat/wtvdec.c
+++ b/libavformat/wtvdec.c
@@ -368,28 +368,30 @@ static int read_probe(AVProbeData *p)
 
 /**
  * Convert win32 FILETIME to ISO-8601 string
+ * @return <0 on error
  */
-static void filetime_to_iso8601(char *buf, int buf_size, int64_t value)
+static int filetime_to_iso8601(char *buf, int buf_size, int64_t value)
 {
     time_t t = (value / 10000000LL) - 11644473600LL;
     struct tm *tm = gmtime(&t);
-    if (tm)
-        strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
-    else
-        buf[0] = '\0';
+    if (!tm)
+        return -1;
+    strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
+    return 0;
 }
 
 /**
  * Convert crazy time (100ns since 1 Jan 0001) to ISO-8601 string
+ * @return <0 on error
  */
-static void crazytime_to_iso8601(char *buf, int buf_size, int64_t value)
+static int crazytime_to_iso8601(char *buf, int buf_size, int64_t value)
 {
     time_t t = (value / 10000000LL) - 719162LL*86400LL;
     struct tm *tm = gmtime(&t);
-    if (tm)
-        strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
-    else
-        buf[0] = '\0';
+    if (!tm)
+        return -1;
+    strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
+    return 0;
 }
 
 /**
@@ -460,10 +462,16 @@ static void get_tag(AVFormatContext *s, AVIOContext *pb, const char *key, int ty
         int64_t num = avio_rl64(pb);
         if (!strcmp(key, "WM/EncodingTime") ||
             !strcmp(key, "WM/MediaOriginalBroadcastDateTime"))
-            filetime_to_iso8601(buf, buf_size, num);
+            if (filetime_to_iso8601(buf, buf_size, num) < 0) {
+                av_free(buf);
+                return;
+            }
         else if (!strcmp(key, "WM/WMRVEncodeTime") ||
                  !strcmp(key, "WM/WMRVEndTime"))
-            crazytime_to_iso8601(buf, buf_size, num);
+            if (crazytime_to_iso8601(buf, buf_size, num) < 0) {
+                av_free(buf);
+                return;
+            }
         else if (!strcmp(key, "WM/WMRVExpirationDate")) {
             if (oledate_to_iso8601(buf, buf_size, num) < 0 ) {
                 av_free(buf);
-- 
1.7.10.4

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120702/0bb33a2c/attachment.asc>


More information about the ffmpeg-devel mailing list