applehttp: Only check the discard flags if v->ctx actually is initialized

Message ID 1302595042-91480-1-git-send-email-martin@martin.st
State Committed
Commit a92a7ddc253a640aba974d859eab20d74cebb3e0
Headers show

Commit Message

Martin Storsjö April 12, 2011, 7:57 a.m.
This code could be executed if the demuxer reads more than one
segment before returning from av_open_input_stream.
---
 libavformat/applehttp.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

Comments

Ronald Bultje April 13, 2011, 1:19 a.m. | #1
Hi Martin,

On Tue, Apr 12, 2011 at 3:57 AM, Martin Storsjö <martin@martin.st> wrote:
> This code could be executed if the demuxer reads more than one
> segment before returning from av_open_input_stream.
> ---
>  libavformat/applehttp.c |   11 +++++++----
>  1 files changed, 7 insertions(+), 4 deletions(-)

Is this a real issue?

Looks OK to me, maybe a warning would be nice otherwise (does it miss
data otherwise, or does it only happen during preroll stage?).

Ronald
Martin Storsjö April 13, 2011, 6:39 a.m. | #2
On Tue, 12 Apr 2011, Ronald S. Bultje wrote:

> On Tue, Apr 12, 2011 at 3:57 AM, Martin Storsjö <martin@martin.st> wrote:
> > This code could be executed if the demuxer reads more than one
> > segment before returning from av_open_input_stream.
> > ---
> >  libavformat/applehttp.c |   11 +++++++----
> >  1 files changed, 7 insertions(+), 4 deletions(-)
> 
> Is this a real issue?

I haven't seen it occur in practice (yet), but I ran into it while testing 
the AES crypto support - if unable to probe the stream reliably, it will 
read more than one segment, and currently it will crash at that point.

> Looks OK to me, maybe a warning would be nice otherwise (does it miss
> data otherwise, or does it only happen during preroll stage?).

This isn't really something (in itself) to warn the user about - if the 
segments are too short for the demuxer to open with only one segment, just 
continue with the next one, as we would do otherwise. Just don't try to do 
the "allow bitrate switching between segments" logic at this point, since 
we aren't at a stage where that makes sense to do yet.

Queued this version then.

// Martin

Patch

diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index 243f4a6..35759be 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -309,10 +309,13 @@  reload:
     c->end_of_segment = 1;
     c->cur_seq_no = v->cur_seq_no;
 
-    v->needed = 0;
-    for (i = v->stream_offset; i < v->stream_offset + v->ctx->nb_streams; i++) {
-        if (v->parent->streams[i]->discard < AVDISCARD_ALL)
-            v->needed = 1;
+    if (v->ctx) {
+        v->needed = 0;
+        for (i = v->stream_offset; i < v->stream_offset + v->ctx->nb_streams;
+             i++) {
+            if (v->parent->streams[i]->discard < AVDISCARD_ALL)
+                v->needed = 1;
+        }
     }
     if (!v->needed) {
         av_log(v->parent, AV_LOG_INFO, "No longer receiving variant %d\n",