[vlc-devel] commit: Fixes bad error checking on read errors. (Eric Petit )

git version control git at videolan.org
Wed Aug 20 09:14:39 CEST 2008


vlc | branch: master | Eric Petit <eric.petit at lapsus.org> | Wed Aug 20 09:15:50 2008 +0200| [f5f434a61e9d0de0f6bcc5fe01bf72d2216739b5] | committer: 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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f5f434a61e9d0de0f6bcc5fe01bf72d2216739b5
---

 modules/access/dvb/access.c       |    3 ++-
 modules/access_filter/timeshift.c |    9 +++++----
 modules/demux/mod.c               |    6 ++++--
 modules/demux/vobsub.c            |    7 ++++---
 src/input/stream.c                |    5 +++--
 5 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/modules/access/dvb/access.c b/modules/access/dvb/access.c
index 0743147..6dc9bed 100644
--- a/modules/access/dvb/access.c
+++ b/modules/access/dvb/access.c
@@ -494,13 +494,14 @@ static block_t *Block( access_t *p_access )
         {
             p_block = block_New( p_access,
                                  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 )
             {
                 msg_Warn( p_access, "read failed (%m)" );
                 block_Release( p_block );
                 continue;
             }
+            p_block->i_buffer = i_ret;
             break;
         }
     }
diff --git a/modules/access_filter/timeshift.c b/modules/access_filter/timeshift.c
index 924744a..b90e261 100644
--- a/modules/access_filter/timeshift.c
+++ b/modules/access_filter/timeshift.c
@@ -285,16 +285,17 @@ static void* Thread( vlc_object_t* p_this )
         }
         else
         {
-            if( ( p_block = block_New( p_access, 2048 ) ) == NULL ) break;
+            int i_read;
 
-            p_block->i_buffer =
-                p_src->pf_read( p_src, p_block->p_buffer, 2048 );
+            if( ( p_block = block_New( p_access, 2048 ) ) == NULL ) break;
 
-            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 );
               p_block = NULL;
             }
+            p_block->i_buffer = i_read;
         }
 
         if( p_block == NULL )
diff --git a/modules/demux/mod.c b/modules/demux/mod.c
index 1261199..399bc00 100644
--- a/modules/demux/mod.c
+++ b/modules/demux/mod.c
@@ -273,16 +273,18 @@ static int Demux( demux_t *p_demux )
     block_t     *p_frame;
     int         i_bk = ( p_sys->fmt.audio.i_bitspersample / 8 ) *
                        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->i_buffer = ModPlug_Read( p_sys->f, p_frame->p_buffer, p_frame->i_buffer );
-    if( p_frame->i_buffer <= 0 )
+    i_read = ModPlug_Read( p_sys->f, p_frame->p_buffer, p_frame->i_buffer );
+    if( i_read <= 0 )
     {
         /* EOF */
         block_Release( p_frame );
         return 0;
     }
+    p_frame->i_buffer = i_read;
 
     /* Set PCR */
     es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int64_t)p_sys->i_time );
diff --git a/modules/demux/vobsub.c b/modules/demux/vobsub.c
index 64c3570..e529939 100644
--- a/modules/demux/vobsub.c
+++ b/modules/demux/vobsub.c
@@ -336,7 +336,7 @@ static int Demux( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     int64_t i_maxdate;
-    int i;
+    int i, i_read;
 
     for( i = 0; i < p_sys->i_tracks; i++ )
     {
@@ -382,13 +382,14 @@ static int Demux( demux_t *p_demux )
             }
 
             /* read data */
-            p_block->i_buffer = stream_Read( p_sys->p_vobsub_stream, p_block->p_buffer, i_size );
-            if( p_block->i_buffer <= 6 )
+            i_read = stream_Read( p_sys->p_vobsub_stream, p_block->p_buffer, i_size );
+            if( i_read <= 6 )
             {
                 block_Release( p_block );
                 tk.i_current_subtitle++;
                 continue;
             }
+            p_block->i_buffer = i_read;
 
             /* pts */
             p_block->i_pts = tk.p_subtitles[tk.i_current_subtitle].i_start;
diff --git a/src/input/stream.c b/src/input/stream.c
index 5cb4aa2..228cfc8 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -2124,9 +2124,10 @@ block_t *stream_Block( stream_t *s, int i_size )
     block_t *p_bk = block_New( s, i_size );
     if( p_bk )
     {
-        p_bk->i_buffer = stream_Read( s, p_bk->p_buffer, i_size );
-        if( p_bk->i_buffer > 0 )
+        int i_read = stream_Read( s, p_bk->p_buffer, i_size );
+        if( i_read > 0 )
         {
+            p_bk->i_buffer = i_read;
             return p_bk;
         }
         block_Release( p_bk );




More information about the vlc-devel mailing list