From 397df13cacbc11d2b164106b7f357b637d13f60e Mon Sep 17 00:00:00 2001 From: Laurent Aimar Date: Mon, 4 May 2009 20:47:32 +0200 Subject: [PATCH] Do not read the whole file (in memory !) when parsing RAR. --- modules/stream_filter/rar.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/stream_filter/rar.c b/modules/stream_filter/rar.c index 791e12f572..a5fd8291f8 100644 --- a/modules/stream_filter/rar.c +++ b/modules/stream_filter/rar.c @@ -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 ) { -- 2.39.2