[FFmpeg-cvslog] avcodec/tak: remove GetBitContext usage from avpriv_tak_parse_streaminfo()

James Almer git at videolan.org
Thu Oct 26 06:51:24 EEST 2017


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sun Oct 22 20:29:53 2017 -0300| [6bd665b7c5798803366b877903fa3bce7f129d05] | committer: James Almer

avcodec/tak: remove GetBitContext usage from avpriv_tak_parse_streaminfo()

This prevents potential ABI issues with GetBitContext.

Reviewed-by: Paul B Mahol <onemda at gmail.com>
Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6bd665b7c5798803366b877903fa3bce7f129d05
---

 libavcodec/tak.c     | 17 +++++++++++++++--
 libavcodec/tak.h     |  8 ++++++--
 libavformat/takdec.c |  7 +++++--
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/libavcodec/tak.c b/libavcodec/tak.c
index d2670e00ff..8aa956b661 100644
--- a/libavcodec/tak.c
+++ b/libavcodec/tak.c
@@ -90,7 +90,7 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size)
     return 0;
 }
 
-void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
+void ff_tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb)
 {
     uint64_t channel_mask = 0;
     int frame_type, i;
@@ -125,6 +125,19 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
     s->frame_samples = tak_get_nb_samples(s->sample_rate, frame_type);
 }
 
+int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size)
+{
+    GetBitContext gb;
+    int ret = init_get_bits8(&gb, buf, size);
+
+    if (ret < 0)
+        return AVERROR_INVALIDDATA;
+
+    ff_tak_parse_streaminfo(s, &gb);
+
+    return 0;
+}
+
 int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
                                TAKStreamInfo *ti, int log_level_offset)
 {
@@ -144,7 +157,7 @@ int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
     }
 
     if (ti->flags & TAK_FRAME_FLAG_HAS_INFO) {
-        avpriv_tak_parse_streaminfo(gb, ti);
+        ff_tak_parse_streaminfo(ti, gb);
 
         if (get_bits(gb, 6))
             skip_bits(gb, 25);
diff --git a/libavcodec/tak.h b/libavcodec/tak.h
index 4fa1239093..dc45a8c070 100644
--- a/libavcodec/tak.h
+++ b/libavcodec/tak.h
@@ -143,10 +143,14 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size);
 
 /**
  * Parse the Streaminfo metadata block.
- * @param[in]  gb pointer to GetBitContext
  * @param[out] s  storage for parsed information
+ * @param[in]  buf   input buffer
+ * @param[in]  size  size of input buffer in bytes
+ * @return non-zero on error, 0 if OK
  */
-void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s);
+int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size);
+
+void ff_tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb);
 
 /**
  * Validate and decode a frame header.
diff --git a/libavformat/takdec.c b/libavformat/takdec.c
index 1535bec64f..6fda35c1be 100644
--- a/libavformat/takdec.c
+++ b/libavformat/takdec.c
@@ -103,7 +103,6 @@ static int tak_read_header(AVFormatContext *s)
                 }
             }
 
-            init_get_bits8(&gb, buffer, size - 3);
             break;
         case TAK_METADATA_MD5: {
             uint8_t md5[16];
@@ -145,7 +144,9 @@ static int tak_read_header(AVFormatContext *s)
         if (type == TAK_METADATA_STREAMINFO) {
             TAKStreamInfo ti;
 
-            avpriv_tak_parse_streaminfo(&gb, &ti);
+            ret = avpriv_tak_parse_streaminfo(&ti, buffer, size -3);
+            if (ret < 0)
+                return AVERROR_INVALIDDATA;
             if (ti.samples > 0)
                 st->duration = ti.samples;
             st->codecpar->bits_per_coded_sample = ti.bps;
@@ -161,11 +162,13 @@ static int tak_read_header(AVFormatContext *s)
         } else if (type == TAK_METADATA_LAST_FRAME) {
             if (size != 11)
                 return AVERROR_INVALIDDATA;
+            init_get_bits8(&gb, buffer, size - 3);
             tc->mlast_frame = 1;
             tc->data_end    = get_bits64(&gb, TAK_LAST_FRAME_POS_BITS) +
                               get_bits(&gb, TAK_LAST_FRAME_SIZE_BITS);
             av_freep(&buffer);
         } else if (type == TAK_METADATA_ENCODER) {
+            init_get_bits8(&gb, buffer, size - 3);
             av_log(s, AV_LOG_VERBOSE, "encoder version: %0X\n",
                    get_bits_long(&gb, TAK_ENCODER_VERSION_BITS));
             av_freep(&buffer);



More information about the ffmpeg-cvslog mailing list