[FFmpeg-devel] lavf/dashdec: Do not use memcpy() to copy a struct

Submitted by Carl Eugen Hoyos on April 21, 2018, 9:03 p.m.

Details

Message ID CAB0OVGrnm60aK3HV90O3G09cQvpHRzdRTnc-aVdXc81Qfht_1A@mail.gmail.com
State New
Headers show

Commit Message

Carl Eugen Hoyos April 21, 2018, 9:03 p.m.
2018-04-18 22:00 GMT+02:00, wm4 <nfxjfg@googlemail.com>:
> On Wed, 18 Apr 2018 21:52:45 +0200
> Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
>
>> From cf7d2aefc1a3b3a2e9f578ede43906ed6ee96bfd Mon Sep 17 00:00:00 2001
>> From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
>> Date: Wed, 18 Apr 2018 19:42:57 +0200
>> Subject: [PATCH] lavf/dashdec: Do not use memcpy() to copy a struct.
>>
>> Fixes a warning:
>> libavformat/dashdec.c:1900:65: warning: argument to 'sizeof' in 'memcpy'
>> call is the same pointer type 'struct fragment *' as the destination;
>> expected 'struct fragment' or an explicit length
>> ---
>>  libavformat/dashdec.c |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
>> index 6304ad9..917fb54 100644
>> --- a/libavformat/dashdec.c
>> +++ b/libavformat/dashdec.c
>> @@ -1897,7 +1897,7 @@ static int init_section_compare_audio(DASHContext
>> *c)
>>
>>  static void copy_init_section(struct representation *rep_dest, struct
>> representation *rep_src)
>>  {
>> -    memcpy(rep_dest->init_section, rep_src->init_section,
>> sizeof(rep_src->init_section));
>> +    *rep_dest->init_section = *rep_src->init_section;
>>      rep_dest->init_sec_buf = av_mallocz(rep_src->init_sec_buf_size);
>>      memcpy(rep_dest->init_sec_buf, rep_src->init_sec_buf,
>> rep_src->init_sec_data_len);
>>      rep_dest->init_sec_buf_size = rep_src->init_sec_buf_size;
>
> Probably not complete, because it doesn't copy the url field.

I don't disagree but failed to test my attached approach.

Patch applied, Carl Eugen

Patch hide | download patch | download mbox

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index 6304ad9..c1b3131 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -1895,14 +1895,27 @@  static int init_section_compare_audio(DASHContext *c)
     return 1;
 }
 
-static void copy_init_section(struct representation *rep_dest, struct representation *rep_src)
+static int copy_init_section(struct representation *rep_dest, struct representation *rep_src)
 {
+    void *buf, *buf2;
+    buf  = av_mallocz(rep_src->init_section->size);
+    if (!buf)
+        return AVERROR(ENOMEM);
+    buf2 = av_mallocz(rep_src->init_sec_buf_size);
+    if (!buf2) {
+        av_free(buf);
+        return AVERROR(ENOMEM);
+    }
     *rep_dest->init_section = *rep_src->init_section;
+    rep_dest->init_section->url = buf;
+    memcpy(rep_dest->init_section->url, rep_src->init_section->url, rep_src->init_section->size);
-    rep_dest->init_sec_buf = av_mallocz(rep_src->init_sec_buf_size);
+    rep_dest->init_sec_buf = buf2;
     memcpy(rep_dest->init_sec_buf, rep_src->init_sec_buf, rep_src->init_sec_data_len);
     rep_dest->init_sec_buf_size = rep_src->init_sec_buf_size;
     rep_dest->init_sec_data_len = rep_src->init_sec_data_len;
     rep_dest->cur_timestamp = rep_src->cur_timestamp;
+
+    return 0;
 }
 
 
@@ -1942,7 +1955,9 @@  static int dash_read_header(AVFormatContext *s)
     for (i = 0; i < c->n_videos; i++) {
         struct representation *cur_video = c->videos[i];
         if (i > 0 && c->is_init_section_common_video) {
-            copy_init_section(cur_video,c->videos[0]);
+            ret = copy_init_section(cur_video,c->videos[0]);
+            if (ret < 0)
+                return ret;
         }
         ret = open_demux_for_component(s, cur_video);
 
@@ -1959,7 +1974,9 @@  static int dash_read_header(AVFormatContext *s)
     for (i = 0; i < c->n_audios; i++) {
         struct representation *cur_audio = c->audios[i];
         if (i > 0 && c->is_init_section_common_audio) {
-            copy_init_section(cur_audio,c->audios[0]);
+            ret = copy_init_section(cur_audio,c->audios[0]);
+            if (ret < 0)
+                return ret;
         }
         ret = open_demux_for_component(s, cur_audio);