Commit f5f434a6 authored by Eric Petit's avatar Eric Petit

Fixes bad error checking on read errors.

Don't use "p_block->i_buffer = read(...)", i_buffer is unsigned so you
won't catch read errors and will end up crashing using a 4GB buffer
instead. This fixes a DVB segv I was seeing.
parent 538ec8f8
...@@ -494,13 +494,14 @@ static block_t *Block( access_t *p_access ) ...@@ -494,13 +494,14 @@ static block_t *Block( access_t *p_access )
{ {
p_block = block_New( p_access, p_block = block_New( p_access,
p_sys->i_read_once * TS_PACKET_SIZE ); p_sys->i_read_once * TS_PACKET_SIZE );
if( ( p_block->i_buffer = read( p_sys->i_handle, p_block->p_buffer, if( ( i_ret = read( p_sys->i_handle, p_block->p_buffer,
p_sys->i_read_once * TS_PACKET_SIZE ) ) <= 0 ) p_sys->i_read_once * TS_PACKET_SIZE ) ) <= 0 )
{ {
msg_Warn( p_access, "read failed (%m)" ); msg_Warn( p_access, "read failed (%m)" );
block_Release( p_block ); block_Release( p_block );
continue; continue;
} }
p_block->i_buffer = i_ret;
break; break;
} }
} }
......
...@@ -285,16 +285,17 @@ static void* Thread( vlc_object_t* p_this ) ...@@ -285,16 +285,17 @@ static void* Thread( vlc_object_t* p_this )
} }
else else
{ {
if( ( p_block = block_New( p_access, 2048 ) ) == NULL ) break; int i_read;
p_block->i_buffer = if( ( p_block = block_New( p_access, 2048 ) ) == NULL ) break;
p_src->pf_read( p_src, p_block->p_buffer, 2048 );
if( p_block->i_buffer <= 0 ) i_read = p_src->pf_read( p_src, p_block->p_buffer, 2048 );
if( i_read <= 0 )
{ {
block_Release( p_block ); block_Release( p_block );
p_block = NULL; p_block = NULL;
} }
p_block->i_buffer = i_read;
} }
if( p_block == NULL ) if( p_block == NULL )
......
...@@ -273,16 +273,18 @@ static int Demux( demux_t *p_demux ) ...@@ -273,16 +273,18 @@ static int Demux( demux_t *p_demux )
block_t *p_frame; block_t *p_frame;
int i_bk = ( p_sys->fmt.audio.i_bitspersample / 8 ) * int i_bk = ( p_sys->fmt.audio.i_bitspersample / 8 ) *
p_sys->fmt.audio.i_channels; p_sys->fmt.audio.i_channels;
int i_read;
p_frame = block_New( p_demux, p_sys->fmt.audio.i_rate / 10 * i_bk ); p_frame = block_New( p_demux, p_sys->fmt.audio.i_rate / 10 * i_bk );
p_frame->i_buffer = ModPlug_Read( p_sys->f, p_frame->p_buffer, p_frame->i_buffer ); i_read = ModPlug_Read( p_sys->f, p_frame->p_buffer, p_frame->i_buffer );
if( p_frame->i_buffer <= 0 ) if( i_read <= 0 )
{ {
/* EOF */ /* EOF */
block_Release( p_frame ); block_Release( p_frame );
return 0; return 0;
} }
p_frame->i_buffer = i_read;
/* Set PCR */ /* Set PCR */
es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int64_t)p_sys->i_time ); es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int64_t)p_sys->i_time );
......
...@@ -336,7 +336,7 @@ static int Demux( demux_t *p_demux ) ...@@ -336,7 +336,7 @@ static int Demux( demux_t *p_demux )
{ {
demux_sys_t *p_sys = p_demux->p_sys; demux_sys_t *p_sys = p_demux->p_sys;
int64_t i_maxdate; int64_t i_maxdate;
int i; int i, i_read;
for( i = 0; i < p_sys->i_tracks; i++ ) for( i = 0; i < p_sys->i_tracks; i++ )
{ {
...@@ -382,13 +382,14 @@ static int Demux( demux_t *p_demux ) ...@@ -382,13 +382,14 @@ static int Demux( demux_t *p_demux )
} }
/* read data */ /* read data */
p_block->i_buffer = stream_Read( p_sys->p_vobsub_stream, p_block->p_buffer, i_size ); i_read = stream_Read( p_sys->p_vobsub_stream, p_block->p_buffer, i_size );
if( p_block->i_buffer <= 6 ) if( i_read <= 6 )
{ {
block_Release( p_block ); block_Release( p_block );
tk.i_current_subtitle++; tk.i_current_subtitle++;
continue; continue;
} }
p_block->i_buffer = i_read;
/* pts */ /* pts */
p_block->i_pts = tk.p_subtitles[tk.i_current_subtitle].i_start; p_block->i_pts = tk.p_subtitles[tk.i_current_subtitle].i_start;
......
...@@ -2124,9 +2124,10 @@ block_t *stream_Block( stream_t *s, int i_size ) ...@@ -2124,9 +2124,10 @@ block_t *stream_Block( stream_t *s, int i_size )
block_t *p_bk = block_New( s, i_size ); block_t *p_bk = block_New( s, i_size );
if( p_bk ) if( p_bk )
{ {
p_bk->i_buffer = stream_Read( s, p_bk->p_buffer, i_size ); int i_read = stream_Read( s, p_bk->p_buffer, i_size );
if( p_bk->i_buffer > 0 ) if( i_read > 0 )
{ {
p_bk->i_buffer = i_read;
return p_bk; return p_bk;
} }
block_Release( p_bk ); block_Release( p_bk );
......
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