Commit fdfa2f5e authored by Gildas Bazin's avatar Gildas Bazin

* src/input/input_ext-dec.c: added a few sanity checks that avoid crashing
   badly when we reach the end of the stream (decoder stream).
* modules/packetizer/mpegvideo.c: fixed a bug that was causing an infinite
   loop when the end of the stream was reached.
parent 15d3d8ef
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mpegvideo.c * mpegvideo.c
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: mpegvideo.c,v 1.8 2003/01/23 15:52:04 sam Exp $ * $Id: mpegvideo.c,v 1.9 2003/02/26 13:51:36 gbazin Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org> * Eric Petit <titer@videolan.org>
...@@ -234,7 +234,8 @@ static void PacketizeThread( packetizer_t *p_pack ) ...@@ -234,7 +234,8 @@ static void PacketizeThread( packetizer_t *p_pack )
/* TODO: store skipped somewhere so can send it to the mux /* TODO: store skipped somewhere so can send it to the mux
* after the input is created */ * after the input is created */
i_skipped = 0; i_skipped = 0;
while( ShowBits( &p_pack->bit_stream, 32 ) != 0x1B3 ) while( ShowBits( &p_pack->bit_stream, 32 ) != 0x1B3 &&
!p_pack->p_fifo->b_die && !p_pack->p_fifo->b_error )
{ {
RemoveBits( &p_pack->bit_stream, 8 ); RemoveBits( &p_pack->bit_stream, 8 );
i_skipped++; i_skipped++;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* input_ext-dec.c: services to the decoders * input_ext-dec.c: services to the decoders
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2001 VideoLAN * Copyright (C) 1998-2001 VideoLAN
* $Id: input_ext-dec.c,v 1.43 2002/12/06 10:10:39 sam Exp $ * $Id: input_ext-dec.c,v 1.44 2003/02/26 13:51:36 gbazin Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -118,6 +118,10 @@ static inline vlc_bool_t _NextDataPacket( decoder_fifo_t * p_fifo, ...@@ -118,6 +118,10 @@ static inline vlc_bool_t _NextDataPacket( decoder_fifo_t * p_fifo,
* and not just a PES header */ * and not just a PES header */
do do
{ {
/* Sanity check. Yes, this can happen if the caller doesn't check
* for p_fifo->b_die beforehand. */
if( p_bit_stream->p_pes == NULL ) return 0;
/* We were reading the last data packet of this PES packet... It's /* We were reading the last data packet of this PES packet... It's
* time to jump to the next PES packet */ * time to jump to the next PES packet */
if( p_bit_stream->p_data->p_next == NULL ) if( p_bit_stream->p_data->p_next == NULL )
...@@ -215,6 +219,7 @@ u32 UnalignedShowBits( bit_stream_t * p_bit_stream, unsigned int i_bits ) ...@@ -215,6 +219,7 @@ u32 UnalignedShowBits( bit_stream_t * p_bit_stream, unsigned int i_bits )
else else
{ {
_BitstreamNextDataPacket( p_bit_stream ); _BitstreamNextDataPacket( p_bit_stream );
if( p_bit_stream->p_decoder_fifo->b_die ) return 0;
if( (ptrdiff_t)p_bit_stream->p_byte & (sizeof(WORD_TYPE) - 1) ) if( (ptrdiff_t)p_bit_stream->p_byte & (sizeof(WORD_TYPE) - 1) )
{ {
...@@ -240,6 +245,7 @@ u32 UnalignedShowBits( bit_stream_t * p_bit_stream, unsigned int i_bits ) ...@@ -240,6 +245,7 @@ u32 UnalignedShowBits( bit_stream_t * p_bit_stream, unsigned int i_bits )
{ {
j = i; j = i;
_BitstreamNextDataPacket( p_bit_stream ); _BitstreamNextDataPacket( p_bit_stream );
if( p_bit_stream->p_decoder_fifo->b_die ) return 0;
} }
((byte_t *)&p_bit_stream->i_showbits_buffer)[i] = ((byte_t *)&p_bit_stream->i_showbits_buffer)[i] =
* p_bit_stream->p_byte; * p_bit_stream->p_byte;
...@@ -297,6 +303,7 @@ u32 UnalignedGetBits( bit_stream_t * p_bit_stream, unsigned int i_bits ) ...@@ -297,6 +303,7 @@ u32 UnalignedGetBits( bit_stream_t * p_bit_stream, unsigned int i_bits )
else else
{ {
_BitstreamNextDataPacket( p_bit_stream ); _BitstreamNextDataPacket( p_bit_stream );
if( p_bit_stream->p_decoder_fifo->b_die ) return 0;
i_result |= *(p_bit_stream->p_byte++) << (i_bits - 8); i_result |= *(p_bit_stream->p_byte++) << (i_bits - 8);
i_bits -= 8; i_bits -= 8;
} }
...@@ -317,6 +324,7 @@ u32 UnalignedGetBits( bit_stream_t * p_bit_stream, unsigned int i_bits ) ...@@ -317,6 +324,7 @@ u32 UnalignedGetBits( bit_stream_t * p_bit_stream, unsigned int i_bits )
else else
{ {
_BitstreamNextDataPacket( p_bit_stream ); _BitstreamNextDataPacket( p_bit_stream );
if( p_bit_stream->p_decoder_fifo->b_die ) return 0;
i_result |= *p_bit_stream->p_byte >> i_tmp; i_result |= *p_bit_stream->p_byte >> i_tmp;
p_bit_stream->fifo.buffer = *(p_bit_stream->p_byte++) p_bit_stream->fifo.buffer = *(p_bit_stream->p_byte++)
<< ( sizeof(WORD_TYPE) * 8 - i_tmp ); << ( sizeof(WORD_TYPE) * 8 - i_tmp );
...@@ -359,6 +367,7 @@ void UnalignedRemoveBits( bit_stream_t * p_bit_stream ) ...@@ -359,6 +367,7 @@ void UnalignedRemoveBits( bit_stream_t * p_bit_stream )
else else
{ {
_BitstreamNextDataPacket( p_bit_stream ); _BitstreamNextDataPacket( p_bit_stream );
if( p_bit_stream->p_decoder_fifo->b_die ) return;
p_bit_stream->p_byte++; p_bit_stream->p_byte++;
p_bit_stream->fifo.i_available += 8; p_bit_stream->fifo.i_available += 8;
} }
...@@ -377,6 +386,7 @@ void UnalignedRemoveBits( bit_stream_t * p_bit_stream ) ...@@ -377,6 +386,7 @@ void UnalignedRemoveBits( bit_stream_t * p_bit_stream )
else else
{ {
_BitstreamNextDataPacket( p_bit_stream ); _BitstreamNextDataPacket( p_bit_stream );
if( p_bit_stream->p_decoder_fifo->b_die ) return;
p_bit_stream->fifo.buffer = *(p_bit_stream->p_byte++) p_bit_stream->fifo.buffer = *(p_bit_stream->p_byte++)
<< ( sizeof(WORD_TYPE) * 8 - 8 << ( sizeof(WORD_TYPE) * 8 - 8
- p_bit_stream->fifo.i_available ); - p_bit_stream->fifo.i_available );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment