[FFmpeg-devel] [PATCH] dpx.c: Better support for reading fps from headers

Bob Maple bobm-ffdev at burner.com
Mon Jul 7 08:29:43 CEST 2014


On 7/4/2014 7:52 AM, Michael Niedermayer wrote:

>> -    if (offset >= 1724 + 4) {
>> -        buf = avpkt->data + 1724;

> you are removing an out of array access check
> this is not ok unless theres some other check somewhere that makes
> it redundant

Oops.. hmm I actually had changed the avpkt->size check at the head of
the whole function at one point, but must not have saved or something.
Not sure what the hell I did.

Anyway here's a new one with that change;  The whole header on a DPX
should be at least 2k (the Film Info and TV Info headers are required to
be present, but not required to be filled in with anything useful.)

-------------- next part --------------
>From 5943ab521672d708450614d2d8cee59d5a5c32ea Mon Sep 17 00:00:00 2001
From: Bob Maple <bobm-ffdev at burner.com>
Date: Sun, 6 Jul 2014 13:43:30 -0600
Subject: [PATCH] Better support for reading fps from headers

---
 libavcodec/dpx.c |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index 5f05cd8..d296d73 100644
--- a/libavcodec/dpx.c
+++ b/libavcodec/dpx.c
@@ -84,7 +84,7 @@ static int decode_frame(AVCodecContext *avctx,
     unsigned int rgbBuffer = 0;
     int n_datum = 0;
 
-    if (avpkt->size <= 1634) {
+    if (avpkt->size < 2048) {
         av_log(avctx, AV_LOG_ERROR, "Packet too small for DPX header\n");
         return AVERROR_INVALIDDATA;
     }
@@ -147,14 +147,21 @@ static int decode_frame(AVCodecContext *avctx,
     else
         avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
 
-    if (offset >= 1724 + 4) {
-        buf = avpkt->data + 1724;
+    // Look in the 'Film Industry' header and the 'TV Industry' header for fps
+    buf = avpkt->data + 1724;
+    i = read32(&buf, endian);
+
+    // All undefined fields are supposed to be set to all 0xFF
+    // but some writers use +inf here
+    if (i == 0x7F800000 || i == 0xFFFFFFFF) {
+        buf = avpkt->data + 1940;
         i = read32(&buf, endian);
-        if(i) {
-            AVRational q = av_d2q(av_int2float(i), 4096);
-            if (q.num > 0 && q.den > 0)
-                avctx->time_base = av_inv_q(q);
-        }
+    }
+
+    if(i) {
+        AVRational q = av_d2q(av_int2float(i), 4096);
+        if (q.num > 0 && q.den > 0)
+            avctx->time_base = av_inv_q(q);
     }
 
     switch (descriptor) {
-- 
1.7.1



More information about the ffmpeg-devel mailing list