[vlc-devel] [PATCH 11/16] demux:asf: make sure the length cannot be negative

Steve Lhomme robux4 at ycbcr.xyz
Thu Jun 7 11:59:55 CEST 2018


---
 modules/demux/asf/asf.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/modules/demux/asf/asf.c b/modules/demux/asf/asf.c
index c2aba4a679..2454fb31cd 100644
--- a/modules/demux/asf/asf.c
+++ b/modules/demux/asf/asf.c
@@ -440,7 +440,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         SeekPrepare( p_demux );
 
-        if( p_sys->b_index && p_sys->i_length > 0 )
+        if( p_sys->b_index && p_sys->i_length != 0 )
         {
             va_list acpy;
             va_copy( acpy, args );
@@ -498,7 +498,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
     case DEMUX_GET_POSITION:
         if( p_sys->i_time == VLC_TS_INVALID ) return VLC_EGENERIC;
-        if( p_sys->i_length > 0 )
+        if( p_sys->i_length != 0 )
         {
             pf = va_arg( args, double * );
             *pf = p_sys->i_time / (double)p_sys->i_length;
@@ -518,7 +518,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         SeekPrepare( p_demux );
 
-        if( p_sys->b_index && p_sys->i_length > 0 )
+        if( p_sys->b_index && p_sys->i_length != 0 )
         {
             va_list acpy;
             va_copy( acpy, args );
@@ -1249,11 +1249,13 @@ static int DemuxInit( demux_t *p_demux )
         /* calculate the time duration in micro-s */
         p_sys->i_length = MSFTIME_TO_MTIME(p_sys->p_fp->i_play_duration) *
                    (mtime_t)i_count /
-                   (mtime_t)p_sys->p_fp->i_data_packets_count - p_sys->p_fp->i_preroll * 1000;
-        if( p_sys->i_length < 0 )
+                   (mtime_t)p_sys->p_fp->i_data_packets_count;
+        if( p_sys->i_length <= p_sys->p_fp->i_preroll * 1000 )
             p_sys->i_length = 0;
+        else
+            p_sys->i_length -= p_sys->p_fp->i_preroll * 1000;
 
-        if( p_sys->i_length > 0 )
+        if( p_sys->i_length != 0 )
         {
             p_sys->i_bitrate = 8 * i_size * CLOCK_FREQ / p_sys->i_length;
         }
-- 
2.17.0



More information about the vlc-devel mailing list