[FFmpeg-devel] [PATCH 1/2] wtv: detect ole date overflow

Peter Ross pross at xvid.org
Sun May 8 13:28:23 CEST 2011


---
 libavformat/wtv.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/libavformat/wtv.c b/libavformat/wtv.c
index 795ea39..ee7bdda 100644
--- a/libavformat/wtv.c
+++ b/libavformat/wtv.c
@@ -425,11 +425,16 @@ static void crazytime_to_iso8601(char *buf, int buf_size, int64_t value)
 
 /**
  * Convert OLE DATE to ISO-8601 string
+ * @return <0 on error
  */
-static void oledate_to_iso8601(char *buf, int buf_size, int64_t value)
+static int oledate_to_iso8601(char *buf, int buf_size, int64_t value)
 {
     time_t t = 631112400LL + 86400*av_int2dbl(value);
-    strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
+    struct tm result;
+    if (!gmtime_r(&t, &result))
+        return -1;
+    strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", &result);
+    return 0;
 }
 
 static void get_attachment(AVFormatContext *s, AVIOContext *pb, int length)
@@ -490,9 +495,12 @@ static void get_tag(AVFormatContext *s, AVIOContext *pb, const char *key, int ty
         else if (!strcmp(key, "WM/WMRVEncodeTime") ||
                  !strcmp(key, "WM/WMRVEndTime"))
             crazytime_to_iso8601(buf, buf_size, num);
-        else if (!strcmp(key, "WM/WMRVExpirationDate"))
-            oledate_to_iso8601(buf, buf_size, num);
-        else if (!strcmp(key, "WM/WMRVBitrate"))
+        else if (!strcmp(key, "WM/WMRVExpirationDate")) {
+            if (oledate_to_iso8601(buf, buf_size, num) < 0 ) {
+                av_free(buf);
+                return;
+            }
+        } else if (!strcmp(key, "WM/WMRVBitrate"))
             snprintf(buf, buf_size, "%f", av_int2dbl(num));
         else
             snprintf(buf, buf_size, "%"PRIi64, num);
-- 
1.7.4.1

-- 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/20110508/246b7b58/attachment.asc>


More information about the ffmpeg-devel mailing list