From ca6c02a2e3674479b5ef7954f7c190def7f091bf Mon Sep 17 00:00:00 2001 From: Sam Hocevar <sam@videolan.org> Date: Sun, 30 Dec 2001 04:26:53 +0000 Subject: [PATCH] * Fixed a segfault at EOF in input_es.c and input_ts.c (when i_read == 0). * Improved error recovery and avoided memleaks in the various input plugins. * Fixed a deadloop inserted by someone else into input_vcd.c :-) --- plugins/dvd/input_dvd.c | 5 ++++- plugins/dvdread/input_dvdread.c | 4 +++- plugins/mpeg_system/input_es.c | 14 ++++++-------- plugins/mpeg_system/input_ps.c | 3 ++- plugins/mpeg_system/input_ts.c | 23 ++++++----------------- plugins/vcd/input_vcd.c | 11 ++++++++--- 6 files changed, 29 insertions(+), 31 deletions(-) diff --git a/plugins/dvd/input_dvd.c b/plugins/dvd/input_dvd.c index a7fc2b20cd..0876139a7b 100644 --- a/plugins/dvd/input_dvd.c +++ b/plugins/dvd/input_dvd.c @@ -9,7 +9,7 @@ * -dvd_udf to find files ***************************************************************************** * Copyright (C) 1998-2001 VideoLAN - * $Id: input_dvd.c,v 1.114 2001/12/29 15:40:53 massiot Exp $ + * $Id: input_dvd.c,v 1.115 2001/12/30 04:26:53 sam Exp $ * * Author: St�phane Borel <stef@via.ecp.fr> * @@ -216,6 +216,7 @@ static void DVDInit( input_thread_t * p_input ) if( dvdcss_seek( p_dvd->dvdhandle, 0, DVDCSS_NOFLAGS ) < 0 ) { intf_ErrMsg( "dvd error: %s", dvdcss_error( p_dvd->dvdhandle ) ); + input_BuffersEnd( p_input->p_method_data ); p_input->b_error = 1; return; } @@ -229,6 +230,7 @@ static void DVDInit( input_thread_t * p_input ) intf_ErrMsg( "dvd error: allcation error in ifo" ); dvdcss_close( p_dvd->dvdhandle ); free( p_dvd ); + input_BuffersEnd( p_input->p_method_data ); p_input->b_error = 1; return; } @@ -239,6 +241,7 @@ static void DVDInit( input_thread_t * p_input ) IfoDestroy( p_dvd->p_ifo ); dvdcss_close( p_dvd->dvdhandle ); free( p_dvd ); + input_BuffersEnd( p_input->p_method_data ); p_input->b_error = 1; return; } diff --git a/plugins/dvdread/input_dvdread.c b/plugins/dvdread/input_dvdread.c index 015d92e170..19e5463ec4 100644 --- a/plugins/dvdread/input_dvdread.c +++ b/plugins/dvdread/input_dvdread.c @@ -6,7 +6,7 @@ * It depends on: libdvdread for ifo files and block reading. ***************************************************************************** * Copyright (C) 2001 VideoLAN - * $Id: input_dvdread.c,v 1.10 2001/12/29 22:22:01 massiot Exp $ + * $Id: input_dvdread.c,v 1.11 2001/12/30 04:26:53 sam Exp $ * * Author: St�phane Borel <stef@via.ecp.fr> * @@ -203,6 +203,7 @@ static void DvdReadInit( input_thread_t * p_input ) if( (p_input->p_method_data = input_BuffersInit()) == NULL ) { + free( p_dvd ); p_input->b_error = 1; return; } @@ -216,6 +217,7 @@ static void DvdReadInit( input_thread_t * p_input ) { intf_ErrMsg( "dvdread error: can't open VMG info" ); DVDClose( p_dvd->p_dvdread ); + input_BuffersEnd( p_input->p_method_data ); free( p_dvd ); p_input->b_error = 1; return; diff --git a/plugins/mpeg_system/input_es.c b/plugins/mpeg_system/input_es.c index afa78ed3ea..700a61e82e 100644 --- a/plugins/mpeg_system/input_es.c +++ b/plugins/mpeg_system/input_es.c @@ -2,7 +2,7 @@ * input_es.c: Elementary Stream demux and packet management ***************************************************************************** * Copyright (C) 2001 VideoLAN - * $Id: input_es.c,v 1.9 2001/12/29 03:07:51 massiot Exp $ + * $Id: input_es.c,v 1.10 2001/12/30 04:26:53 sam Exp $ * * Author: Christophe Massiot <massiot@via.ecp.fr> * @@ -222,15 +222,13 @@ static int ESRead( input_thread_t * p_input, * back to the buffer allocator. */ int i_loop; - for( i_loop = 0; i_loop + 1 < i_read; i_loop++ ) + for( i_loop = 0; i_loop < i_read; i_loop++ ) { - p_data = p_data->p_next; - } - p_input->pf_delete_packet( p_input->p_method_data, p_data->p_next ); - if( i_read != 0 ) - { - p_data->p_next = NULL; + pp_data = &(*pp_data)->p_next; } + + p_input->pf_delete_packet( p_input->p_method_data, *pp_data ); + *pp_data = NULL; } return( i_read ); diff --git a/plugins/mpeg_system/input_ps.c b/plugins/mpeg_system/input_ps.c index 9090c7592c..ef714e2df2 100644 --- a/plugins/mpeg_system/input_ps.c +++ b/plugins/mpeg_system/input_ps.c @@ -2,7 +2,7 @@ * input_ps.c: PS demux and packet management ***************************************************************************** * Copyright (C) 1998-2001 VideoLAN - * $Id: input_ps.c,v 1.9 2001/12/29 03:07:51 massiot Exp $ + * $Id: input_ps.c,v 1.10 2001/12/30 04:26:53 sam Exp $ * * Authors: Christophe Massiot <massiot@via.ecp.fr> * Cyril Deguet <asmax@via.ecp.fr> @@ -181,6 +181,7 @@ static void PSInit( input_thread_t * p_input ) if( p_input->p_stream == NULL ) { intf_ErrMsg( "Cannot open file (%s)", strerror(errno) ); + input_BuffersEnd( p_input->p_method_data ); p_input->b_error = 1; return; } diff --git a/plugins/mpeg_system/input_ts.c b/plugins/mpeg_system/input_ts.c index e18cd44cb3..fe1254ebda 100644 --- a/plugins/mpeg_system/input_ts.c +++ b/plugins/mpeg_system/input_ts.c @@ -2,7 +2,7 @@ * input_ts.c: TS demux and netlist management ***************************************************************************** * Copyright (C) 1998-2001 VideoLAN - * $Id: input_ts.c,v 1.8 2001/12/29 03:07:51 massiot Exp $ + * $Id: input_ts.c,v 1.9 2001/12/30 04:26:53 sam Exp $ * * Authors: Henri Fallon <henri@videolan.org> * @@ -325,33 +325,22 @@ static int TSRead( input_thread_t * p_input, i_read /= TS_PACKET_SIZE; /* Check correct TS header */ - for( i_loop = 0; i_loop + 1 < i_read; i_loop++ ) + for( i_loop = 0; i_loop < i_read; i_loop++ ) { - if( p_data->p_demux_start[0] != 0x47 ) + if( (*pp_data)->p_demux_start[0] != 0x47 ) { intf_ErrMsg( "input error: bad TS packet (starts with " "0x%.2x, should be 0x47)", p_data->p_demux_start[0] ); } - p_data = p_data->p_next; - } - - /* Last packet */ - if( p_data->p_demux_start[0] != 0x47 ) - { - intf_ErrMsg( "input error: bad TS packet (starts with " - "0x%.2x, should be 0x47)", - p_data->p_demux_start[0] ); + pp_data = &(*pp_data)->p_next; } if( i_read != TS_READ_ONCE ) { /* Delete remaining packets */ - p_input->pf_delete_packet( p_input->p_method_data, p_data->p_next ); - if( i_read != 0 ) - { - p_data->p_next = NULL; - } + p_input->pf_delete_packet( p_input->p_method_data, *pp_data ); + *pp_data = NULL; } } return( i_read ); diff --git a/plugins/vcd/input_vcd.c b/plugins/vcd/input_vcd.c index 333e9a4aaf..b1e691b82a 100644 --- a/plugins/vcd/input_vcd.c +++ b/plugins/vcd/input_vcd.c @@ -241,6 +241,9 @@ static void VCDInit( input_thread_t * p_input ) if ( VCDReadToc( p_vcd ) == -1 ) { intf_ErrMsg( "vcd error: could not read TOC" ); + input_BuffersEnd( p_input->p_method_data ); + p_input->b_error = 1; + return; } /* Set stream and area data */ @@ -413,8 +416,7 @@ static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_data ) i_packet = 0; *pp_data = NULL; - while( i_packet < VCD_DATA_ONCE - && !p_vcd->b_end_of_track ) + while( i_packet < VCD_DATA_ONCE && !p_vcd->b_end_of_track ) { if ( VCDReadSector( p_vcd, p_buffer ) == -1 ) { @@ -436,7 +438,8 @@ static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_data ) /* It is common for MPEG-1 streams to pad with zeros * (although it is forbidden by the recommendation), so * don't bother everybody in this case. */ - intf_WarnMsg( 3, "vcd warning: garbage at input" ); + intf_WarnMsg( 12, "vcd warning: garbage at input" ); + break; } while( (i_header & 0xFFFFFF00) != 0x100L @@ -524,6 +527,8 @@ static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_data ) /* Give the packet to the other input stages. */ *pp_data = p_data; pp_data = &p_data->p_next; + + i_packet++; } } -- 2.25.4