[vlc-devel] [PATCH 5a/5] stream_ReadLine: control maximum length with object variable

Pierre Ynard linkfanel at yahoo.fr
Sun Sep 6 04:46:36 CEST 2020


Very long lines are occasionally encountered in text web resources such
as HTML, JSON or other API data, which the current hardcoded limit can't
accommodate. This allows the caller to configure that limit to do so.

The default remains unchanged at 200 kB. As foremost consumers of those
web resources, lua streams raise the limit to 4 MB, which should be
sufficient to support more than most of them, but still reasonable to
prevent any issue.

This patch applies on top of patch 4, with patch 5b as an alternative to
it. This approach has the advantage of not breaking the ABI or adding
new symbols, which makes it friendly towards 3.0 - which needs the fix.

Fixes #24957 (YouTube playback)


diff --git a/modules/lua/libs/stream.c b/modules/lua/libs/stream.c
index 29ac68a..64e6ee1 100644
--- a/modules/lua/libs/stream.c
+++ b/modules/lua/libs/stream.c
@@ -91,6 +91,8 @@ static int vlclua_stream_new( lua_State *L )
     vlc_object_t * p_this = vlclua_get_this( L );
     const char * psz_url = luaL_checkstring( L, 1 );
     stream_t *p_stream = vlc_stream_NewMRL( p_this, psz_url );
+    if ( p_stream != NULL )
+        var_SetInteger( p_stream, "readline-maxlength", STREAM_LINE_MAX );
     return vlclua_stream_new_inner( L, p_stream );
 }
 
diff --git a/modules/lua/stream_filter.c b/modules/lua/stream_filter.c
index cc4bd29..afb805a 100644
--- a/modules/lua/stream_filter.c
+++ b/modules/lua/stream_filter.c
@@ -311,6 +311,9 @@ int Import_LuaPlaylist(vlc_object_t *obj)
 
     s->pf_readdir = ReadDir;
     s->pf_control = access_vaDirectoryControlHelper;
+
+    var_SetInteger(s->s, "readline-maxlength", STREAM_LINE_MAX);
+
     return VLC_SUCCESS;
 }
 
diff --git a/modules/lua/vlc.h b/modules/lua/vlc.h
index 36bcc25..20927ca 100644
--- a/modules/lua/vlc.h
+++ b/modules/lua/vlc.h
@@ -73,6 +73,7 @@ int ReadMeta( demux_meta_t * );
 int FetchMeta( meta_fetcher_t * );
 int FindArt( meta_fetcher_t * );
 
+#define STREAM_LINE_MAX (2048*2048)
 int Import_LuaPlaylist( vlc_object_t * );
 void Close_LuaPlaylist( vlc_object_t * );
 
diff --git a/src/input/stream.c b/src/input/stream.c
index 01d37c7..5023b8e 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -96,6 +96,7 @@ stream_t *vlc_stream_CustomNew(vlc_object_t *parent,
     priv->text.conv = (vlc_iconv_t)(-1);
     priv->text.char_width = 1;
     priv->text.little_endian = false;
+    var_Create(s, "readline-maxlength", VLC_VAR_INTEGER);
 
     return s;
 }
@@ -191,7 +192,9 @@ char *vlc_stream_ReadLine( stream_t *s )
     size_t i_line = 0;
     bool b_data = false;
 
-    size_t i_max = STREAM_LINE_MAX;
+    size_t i_max = var_InheritInteger( s, "readline-maxlength" );
+    if ( i_max == 0 )
+        i_max = STREAM_LINE_MAX;
     /* Prevent integer overflows below */
     i_max = __MIN( i_max, SIZE_MAX / 3 );
 
-- 
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