Oops, I missed that when I allowed the atom to be added to the end of
the extradata, updated.

I'm not sure if logging as an error is appropriate in the case when
the extradata is not large enough, for this to occur the file will
have been truncated somehow and the mov_read_extradata function will
have logged a warning and returned 0. Which at first glance seams
wrong - should mov_read_extradata return something other than 0 in
this case?

Either way it does mean the code could read the wrong value, but
should not crash with the guard in place.

Thanks

Kevin
From c48f8f2d74562e0e3ee9e6d496fc6a1c4320db14 Mon Sep 17 00:00:00 2001
From: Kevin Wheatley <kevin.j.wheat...@gmail.com>
Date: Tue, 17 Feb 2015 11:47:47 +0000
Subject: [PATCH] Add simple ACLR atom reading to set the color range of the incomming
 track for codec's like DNxHD that utilise AVID's proprietary atom.

Added paranoia check for memory reallocation weirdness that might
occur (should never trigger but be defensive)

Signed-off-by: Kevin Wheatley <kevin.j.wheat...@gmail.com>
---
 libavformat/mov.c |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6d2262a..28a140a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1178,6 +1178,40 @@ static int mov_read_ares(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     return mov_read_avid(c, pb, atom);
 }
 
+static int mov_read_aclr(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    int ret = mov_read_avid(c, pb, atom);
+
+    if (!ret && c->fc->nb_streams >= 1) {
+        AVCodecContext *codec = c->fc->streams[c->fc->nb_streams-1]->codec;
+        if (atom.size == 16) {
+            if (codec->extradata_size >= atom.size + 8) {
+                /* This assumes the atom will be at the end of the extradata */
+                const uint8_t range_value = codec->extradata[codec->extradata_size - 5];
+                switch (range_value) {
+                case 1:
+                    codec->color_range = AVCOL_RANGE_MPEG;
+                    break;
+                case 2:
+                    codec->color_range = AVCOL_RANGE_JPEG;
+                    break;
+                default:
+                    av_log(c, AV_LOG_WARNING, "unknown aclr value (%d)\n", range_value);
+                    break;
+                }
+                av_dlog(c, "color_range: %"PRIu8"\n", codec->color_range);
+            } else {
+              /* For some reason the whole atom was not added to the extradata */
+              av_log(c, AV_LOG_ERROR, "aclr not decoded - incomplete extradata size %d\n", codec->extradata_size);
+            }
+        } else {
+            av_log(c, AV_LOG_WARNING, "aclr not decoded - unexpected size %ld\n", atom.size);
+        }
+    }
+
+    return ret;
+}
+
 static int mov_read_svq3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     return mov_read_extradata(c, pb, atom, AV_CODEC_ID_SVQ3);
@@ -3390,7 +3424,7 @@ static int mov_read_free(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 }
 
 static const MOVParseTableEntry mov_default_parse_table[] = {
-{ MKTAG('A','C','L','R'), mov_read_avid },
+{ MKTAG('A','C','L','R'), mov_read_aclr },
 { MKTAG('A','P','R','G'), mov_read_avid },
 { MKTAG('A','A','L','P'), mov_read_avid },
 { MKTAG('A','R','E','S'), mov_read_ares },
-- 
1.7.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to