diff mbox

[FFmpeg-devel,3/3,v2] avformat/hls: Add missing error check for avcodec_parameters_copy()

Message ID 1478472740-2501-1-git-send-email-anssi.hannula@iki.fi
State Accepted
Commit e2193b53eab9f207544a75ebaf51871b7a1a7931
Headers show

Commit Message

Anssi Hannula Nov. 6, 2016, 10:52 p.m. UTC
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
---

07.11.2016, 00:35, Andreas Cadhalpun kirjoitti:
> On 06.11.2016 22:44, Anssi Hannula wrote:
>> Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
>> ---
>>  libavformat/hls.c | 18 ++++++++++++++----
>>  1 file changed, 14 insertions(+), 4 deletions(-)
>>
> 
> This misses checking the return code of the other occurrence of
> set_stream_info_from_input_stream in hls_read_packet.

Argh, true. Here's a new one.


 libavformat/hls.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

Comments

Andreas Cadhalpun Nov. 6, 2016, 11:08 p.m. UTC | #1
On 06.11.2016 23:52, Anssi Hannula wrote:
> Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
> ---
> 
> 07.11.2016, 00:35, Andreas Cadhalpun kirjoitti:
>> On 06.11.2016 22:44, Anssi Hannula wrote:
>>> Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
>>> ---
>>>  libavformat/hls.c | 18 ++++++++++++++----
>>>  1 file changed, 14 insertions(+), 4 deletions(-)
>>>
>>
>> This misses checking the return code of the other occurrence of
>> set_stream_info_from_input_stream in hls_read_packet.
> 
> Argh, true. Here's a new one.
> 
> 
>  libavformat/hls.c | 27 +++++++++++++++++++++------
>  1 file changed, 21 insertions(+), 6 deletions(-)
> 

LGTM.

Best regards,
Andreas
Anssi Hannula Nov. 7, 2016, 5:11 p.m. UTC | #2
07.11.2016, 01:08, Andreas Cadhalpun kirjoitti:
> On 06.11.2016 23:52, Anssi Hannula wrote:
>> Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
>> ---
>>
>> 07.11.2016, 00:35, Andreas Cadhalpun kirjoitti:
>>> On 06.11.2016 22:44, Anssi Hannula wrote:
>>>> Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
>>>> ---
>>>>  libavformat/hls.c | 18 ++++++++++++++----
>>>>  1 file changed, 14 insertions(+), 4 deletions(-)
>>>>
>>>
>>> This misses checking the return code of the other occurrence of
>>> set_stream_info_from_input_stream in hls_read_packet.
>>
>> Argh, true. Here's a new one.
>>
>>
>>  libavformat/hls.c | 27 +++++++++++++++++++++------
>>  1 file changed, 21 insertions(+), 6 deletions(-)
>>
> 
> LGTM.

Thanks, all 3 applied to master and backported to 3.2 branch.
diff mbox

Patch

diff --git a/libavformat/hls.c b/libavformat/hls.c
index ce52bf5..2bf86fa 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -1528,9 +1528,13 @@  static void add_stream_to_programs(AVFormatContext *s, struct playlist *pls, AVS
         av_dict_set_int(&stream->metadata, "variant_bitrate", bandwidth, 0);
 }
 
-static void set_stream_info_from_input_stream(AVStream *st, struct playlist *pls, AVStream *ist)
+static int set_stream_info_from_input_stream(AVStream *st, struct playlist *pls, AVStream *ist)
 {
-    avcodec_parameters_copy(st->codecpar, ist->codecpar);
+    int err;
+
+    err = avcodec_parameters_copy(st->codecpar, ist->codecpar);
+    if (err < 0)
+        return err;
 
     if (pls->is_id3_timestamped) /* custom timestamps via id3 */
         avpriv_set_pts_info(st, 33, 1, MPEG_TIME_BASE);
@@ -1538,11 +1542,15 @@  static void set_stream_info_from_input_stream(AVStream *st, struct playlist *pls
         avpriv_set_pts_info(st, ist->pts_wrap_bits, ist->time_base.num, ist->time_base.den);
 
     st->internal->need_context_update = 1;
+
+    return 0;
 }
 
 /* add new subdemuxer streams to our context, if any */
 static int update_streams_from_subdemuxer(AVFormatContext *s, struct playlist *pls)
 {
+    int err;
+
     while (pls->n_main_streams < pls->ctx->nb_streams) {
         int ist_idx = pls->n_main_streams;
         AVStream *st = avformat_new_stream(s, NULL);
@@ -1552,11 +1560,13 @@  static int update_streams_from_subdemuxer(AVFormatContext *s, struct playlist *p
             return AVERROR(ENOMEM);
 
         st->id = pls->index;
-        set_stream_info_from_input_stream(st, pls, ist);
-
         dynarray_add(&pls->main_streams, &pls->n_main_streams, st);
 
         add_stream_to_programs(s, pls, st);
+
+        err = set_stream_info_from_input_stream(st, pls, ist);
+        if (err < 0)
+            return err;
     }
 
     return 0;
@@ -1990,8 +2000,13 @@  static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
 
         /* There may be more situations where this would be useful, but this at least
          * handles newly probed codecs properly (i.e. request_probe by mpegts). */
-        if (ist->codecpar->codec_id != st->codecpar->codec_id)
-            set_stream_info_from_input_stream(st, pls, ist);
+        if (ist->codecpar->codec_id != st->codecpar->codec_id) {
+            ret = set_stream_info_from_input_stream(st, pls, ist);
+            if (ret < 0) {
+                av_packet_unref(pkt);
+                return ret;
+            }
+        }
 
         return 0;
     }