]> git.sesse.net Git - vlc/blobdiff - modules/demux/avi/avi.c
demux: avi: improve broken index offset heuristic (fix #14120)
[vlc] / modules / demux / avi / avi.c
index ef783d9c797e346b6be31980f4a3dbac17e59d74..34a33621814b7c32b7006873d9488ca31b7ec827 100644 (file)
@@ -446,6 +446,11 @@ static int Open( vlc_object_t * p_this )
                     tk->i_blocksize = 0; /* fix vorbis VBR decoding */
                 }
 
+                if ( tk->i_codec == VLC_CODEC_MP4A )
+                {
+                    tk->i_samplesize = 0; /* ADTS/AAC VBR */
+                }
+
                 es_format_Init( &fmt, AUDIO_ES, tk->i_codec );
 
                 fmt.audio.i_channels        = p_auds->p_wf->nChannels;
@@ -713,9 +718,6 @@ aviindex:
                           (mtime_t)p_avih->i_microsecperframe /
                           CLOCK_FREQ )
     {
-        if( !vlc_object_alive( p_demux) )
-            goto error;
-
         msg_Warn( p_demux, "broken or missing index, 'seek' will be "
                            "approximative or will exhibit strange behavior" );
         if( (i_do_index == 0 || i_do_index == 3) && !b_index )
@@ -1123,7 +1125,6 @@ static int Demux_Seekable( demux_t *p_demux )
                      * affect the reading speed too much. */
                     if( !(++i_loop_count % 1024) )
                     {
-                        if( !vlc_object_alive (p_demux) ) return -1;
                         msleep( 10000 );
 
                         if( !(i_loop_count % (1024 * 10)) )
@@ -1770,8 +1771,6 @@ static int AVI_StreamChunkFind( demux_t *p_demux, unsigned int i_stream )
 
     for( ;; )
     {
-        if( !vlc_object_alive (p_demux) ) return VLC_EGENERIC;
-
         if( AVI_PacketGetHeader( p_demux, &avi_pk ) )
         {
             msg_Warn( p_demux, "cannot get packet header" );
@@ -1790,7 +1789,6 @@ static int AVI_StreamChunkFind( demux_t *p_demux, unsigned int i_stream )
              * affect the reading speed too much. */
             if( !(++i_loop_count % 1024) )
             {
-                if( !vlc_object_alive (p_demux) ) return VLC_EGENERIC;
                 msleep( 10000 );
 
                 if( !(i_loop_count % (1024 * 10)) )
@@ -2228,8 +2226,6 @@ static int AVI_PacketSearch( demux_t *p_demux )
          * this code is called only on broken files). */
         if( !(++i_count % 1024) )
         {
-            if( !vlc_object_alive (p_demux) ) return VLC_EGENERIC;
-
             msleep( 10000 );
             if( !(i_count % (1024 * 10)) )
                 msg_Warn( p_demux, "trying to resync..." );
@@ -2325,11 +2321,22 @@ static int AVI_IndexFind_idx1( demux_t *p_demux,
             *pi_offset = 0;
         else
             *pi_offset = i_movi_content;
+
+        if( p_idx1->i_entry_count )
+        {
+            /* Invalidate offset if index refers past the data section to avoid false
+               positives when the offset equals sample size */
+            size_t i_dataend = *pi_offset + p_idx1->entry[p_idx1->i_entry_count - 1].i_pos +
+                                            p_idx1->entry[p_idx1->i_entry_count - 1].i_length;
+            if( i_dataend > p_movi->i_chunk_pos + p_movi->i_chunk_size )
+                *pi_offset = 0;
+        }
     }
     else
     {
         *pi_offset = 0;
     }
+
     return VLC_SUCCESS;
 }
 
@@ -2567,9 +2574,6 @@ static void AVI_IndexCreate( demux_t *p_demux )
     {
         avi_packet_t pk;
 
-        if( !vlc_object_alive (p_demux) )
-            break;
-
         /* Don't update/check dialog too often */
         if( p_dialog && mdate() - i_dialog_update > 100000 )
         {