[vlc-devel] [PATCH 4/5] stream_ReadLine: support arbitrary length limit

Pierre Ynard linkfanel at yahoo.fr
Sun Sep 6 04:42:56 CEST 2020


The maximum length isn't a configurable parameter yet.


diff --git a/src/input/stream.c b/src/input/stream.c
index aacba86..01d37c7 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -191,6 +191,10 @@ char *vlc_stream_ReadLine( stream_t *s )
     size_t i_line = 0;
     bool b_data = false;
 
+    size_t i_max = STREAM_LINE_MAX;
+    /* Prevent integer overflows below */
+    i_max = __MIN( i_max, SIZE_MAX / 3 );
+
     /* Let's fail quickly if this is a readdir access */
     if( s->pf_read == NULL && s->pf_block == NULL )
         return NULL;
@@ -202,7 +206,8 @@ char *vlc_stream_ReadLine( stream_t *s )
         ssize_t i_data;
 
         /* Probe new data */
-        i_data = vlc_stream_Peek( s, &p_data, STREAM_PROBE_LINE );
+        i_data = vlc_stream_Peek( s, &p_data, __MIN( STREAM_PROBE_LINE,
+                                                     i_max - i_line ) );
         if( i_data <= 0 ) break; /* No more data */
 
         /* BOM detection */
@@ -312,7 +317,7 @@ char *vlc_stream_ReadLine( stream_t *s )
             break;
         }
 
-        if( i_line >= STREAM_LINE_MAX )
+        if( i_line + priv->text.char_width > i_max )
         {
             msg_Err( s, "line too long, returning EOF instead" );
             goto error;
-- 
Pierre Ynard
"Une âme dans un corps, c'est comme un dessin sur une feuille de papier."


More information about the vlc-devel mailing list