[vlc-commits] demux: restore stream offset before probing (fixes #18502)

Rémi Denis-Courmont git at videolan.org
Sun Jul 9 15:34:40 CEST 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jul  9 16:29:58 2017 +0300| [11874bc592eb32f8f89075fe59294dc2d0115058] | committer: Rémi Denis-Courmont

demux: restore stream offset before probing (fixes #18502)

There are (roughly) three ways that a demux probe function can fail:
- file type does not match,
- file type matches but corruption is detected early,
- unexpected I/O error.

In the first case, the demuxer will typically not move the "virtual"
file offset - mostly using vlc_stream_Peek(). But in the later two
cases, the demuxer will typically have moved the file offset forward.

There are no generic ways to fix it. Seeking back might fail (leading
to ingored result warning). So we try to fix it in generic way before
trying the next demuxer. If it fails, such as due to unrecoverable I/O
error, we just skip it completely.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=11874bc592eb32f8f89075fe59294dc2d0115058
---

 src/input/demux.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/input/demux.c b/src/input/demux.c
index 83d8b67eea..109a386775 100644
--- a/src/input/demux.c
+++ b/src/input/demux.c
@@ -175,6 +175,22 @@ static void demux_DestroyDemuxFilter(demux_t *demux)
     demux_Delete(demux->p_next);
 }
 
+static int demux_Probe(void *func, va_list ap)
+{
+    int (*probe)(vlc_object_t *) = func;
+    demux_t *demux = va_arg(ap, demux_t *);
+
+    /* Restore input stream offset (in case previous probed demux failed to
+     * to do so). */
+    if (vlc_stream_Tell(demux->s) != 0 && vlc_stream_Seek(demux->s, 0))
+    {
+        msg_Err(demux, "seek failure before probing");
+        return VLC_EGENERIC;
+    }
+
+    return probe(VLC_OBJECT(demux));
+}
+
 /*****************************************************************************
  * demux_NewAdvanced:
  *  if s is NULL then load a access_demux
@@ -245,9 +261,8 @@ demux_t *demux_NewAdvanced( vlc_object_t *p_obj, input_thread_t *p_parent_input,
         if( psz_module == NULL )
             psz_module = p_demux->psz_demux;
 
-        p_demux->p_module =
-            module_need( p_demux, "demux", psz_module,
-                         !strcmp( psz_module, p_demux->psz_demux ) );
+        p_demux->p_module = vlc_module_load(p_demux, "demux", psz_module,
+             !strcmp(psz_module, p_demux->psz_demux), demux_Probe, p_demux);
     }
     else
     {



More information about the vlc-commits mailing list