[vlc-devel] [PATCH 02/11] demux: wav: refactor chunk skip
Remi Denis-Courmont
remi at remlab.net
Thu Mar 12 17:34:06 CET 2020
Le 2020-03-12 16:05, Thomas Guillem a écrit :
> ---
> modules/demux/wav.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/modules/demux/wav.c b/modules/demux/wav.c
> index c68f5e916eb..4f483df10c7 100644
> --- a/modules/demux/wav.c
> +++ b/modules/demux/wav.c
> @@ -116,6 +116,17 @@ static int Control( demux_t *p_demux, int
> i_query, va_list args )
> i_query, args );
> }
>
> +static int ChunkSkip( demux_t *p_demux, size_t i_size )
> +{
> + if( vlc_stream_Read( p_demux->s, NULL, i_size ) != (ssize_t)i_size
> )
> + return VLC_EGENERIC;
Can you really assume that i_size <= SSIZE_MAX here even on 32-bits
platforms?
Also i_size += i_size & 1; would simplify.
> +
> + if( (i_size & 1) && vlc_stream_Read( p_demux->s, NULL, 1 ) != 1 )
> + return VLC_EGENERIC;
> +
> + return VLC_SUCCESS;
> +}
> +
> static int ChunkFind( demux_t *p_demux, const char *fcc, unsigned int
> *pi_size )
> {
> const uint8_t *p_peek;
> @@ -143,10 +154,7 @@ static int ChunkFind( demux_t *p_demux, const
> char *fcc, unsigned int *pi_size )
> return VLC_SUCCESS;
> }
>
> - /* Skip chunk */
> - if( vlc_stream_Read( p_demux->s, NULL, 8 ) != 8 ||
> - vlc_stream_Read( p_demux->s, NULL, i_size ) != (int)i_size
> ||
> - ( (i_size & 1) && vlc_stream_Read( p_demux->s, NULL, 1 )
> != 1 ) )
> + if( ChunkSkip( p_demux, i_size + 8 ) != VLC_SUCCESS )
> return VLC_EGENERIC;
> }
> }
> @@ -302,8 +310,7 @@ static int Open( vlc_object_t * p_this )
> p_sys->i_data_size = (int64_t)1 << 62;
> else
> p_sys->i_data_size = i_data_size;
> - if( vlc_stream_Read( p_demux->s, NULL, i_size ) != (int)i_size
> ||
> - ( (i_size & 1) && vlc_stream_Read( p_demux->s, NULL, 1 )
> != 1 ) )
> + if( ChunkSkip( p_demux, i_size ) != VLC_SUCCESS )
> goto error;
> }
--
Rémi Denis-Courmont
More information about the vlc-devel
mailing list