]> git.sesse.net Git - vlc/commitdiff
Do not read the whole file (in memory !) when parsing RAR.
authorLaurent Aimar <fenrir@videolan.org>
Mon, 4 May 2009 18:47:32 +0000 (20:47 +0200)
committerLaurent Aimar <fenrir@videolan.org>
Mon, 4 May 2009 19:02:04 +0000 (21:02 +0200)
modules/stream_filter/rar.c

index 791e12f57248344118434b917e6e29c678667024..a5fd8291f8bc2b4597fce9359dbf24b4fd2c68b2 100644 (file)
@@ -442,15 +442,15 @@ static int SkipFile( stream_t *s,const rar_block_t *p_hdr )
     stream_sys_t *p_sys = s->p_sys;
     const uint8_t *p_peek;
 
-    if( stream_Peek( s->p_source, &p_peek, p_hdr->i_size ) < p_hdr->i_size )
-        return VLC_EGENERIC;
-
     int i_min_size = 7+21;
     if( p_hdr->i_flags & RAR_BLOCK_FILE_HAS_HIGH )
         i_min_size += 8;
     if( p_hdr->i_size < i_min_size )
         return VLC_EGENERIC;
 
+    if( stream_Peek( s->p_source, &p_peek, i_min_size ) < i_min_size )
+        return VLC_EGENERIC;
+
     /* */
     uint32_t i_file_size_low = GetDWLE( &p_peek[7+4] );
     uint8_t  i_method = p_peek[7+18];
@@ -465,7 +465,15 @@ static int SkipFile( stream_t *s,const rar_block_t *p_hdr )
 
     const int i_name_offset = (p_hdr->i_flags & RAR_BLOCK_FILE_HAS_HIGH) ? (7+33) : (7+25);
     if( i_name_offset + i_name_size <= p_hdr->i_size )
+    {
+        const int i_max_size = i_name_offset + i_name_size;
+        if( stream_Peek( s->p_source, &p_peek, i_max_size ) < i_max_size )
+        {
+            free( psz_name );
+            return VLC_EGENERIC;
+        }
         memcpy( psz_name, &p_peek[i_name_offset], i_name_size );
+    }
 
     if( i_method != 0x30 )
     {