[vlc-commits] [Git][videolan/vlc][3.0.x] access: rist: robustness fixes in receive path and peer config

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Mon Jun 29 18:52:15 UTC 2026



Jean-Baptiste Kempf pushed to branch 3.0.x at VideoLAN / VLC


Commits:
35b498c5 by Sergio Ammirata at 2026-06-29T20:11:44+02:00
access: rist: robustness fixes in receive path and peer config

Fix off-by-one in RIST_MAX_QUEUE_BUFFERS check that could overflow the
rist_items array.  Fix leaked librist data blocks when all received
payloads have zero length (i_total_size == 0) by routing through
failed_cleanup.  Remove the i_total_size > 0 guard in failed_cleanup
since the loop is safe with i_rist_items_index == 0.

Validate the integer config values that are passed to librist's
uint32_t peer config fields: each negative value is now logged via
msg_Warn and clamped to 0.  The retry interval is also clamped to
INT_MAX / 10 before being multiplied by 10 to avoid signed integer
overflow (undefined behaviour).  Parenthesise the (10 * x) cast.

Include <limits.h> explicitly for INT_MAX.

Guard strdup(psz_url) against NULL to avoid undefined behaviour when
no URL is configured.

(cherry picked from commit b6362a2556f6e592b4bd48cb2b9ad8e9a278552b)

- - - - -


2 changed files:

- modules/access/rist.c
- modules/access/rist.h


Changes:

=====================================
modules/access/rist.c
=====================================
@@ -175,8 +175,7 @@ static block_t *BlockRIST(stream_t *p_access, bool *restrict eof)
             break;
         }
         vlc_mutex_unlock( &p_sys->lock );
-        // Make sure we never read more than our array size
-        if (i_rist_items_index == (RIST_MAX_QUEUE_BUFFERS -1))
+        if (i_rist_items_index >= RIST_MAX_QUEUE_BUFFERS)
             break;
     }
 
@@ -190,7 +189,7 @@ static block_t *BlockRIST(stream_t *p_access, bool *restrict eof)
     }
 
     if (i_total_size == 0) {
-        return NULL;
+        goto failed_cleanup;
     }
 
     // Prepare one large buffer (when we are behing in reading, otherwise it is the same size as what is being read)
@@ -209,10 +208,8 @@ static block_t *BlockRIST(stream_t *p_access, bool *restrict eof)
     return pktout;
 
 failed_cleanup:
-    if (i_total_size > 0) {
-        for (size_t i = 0; i < i_rist_items_index; i++) {
-            rist_receiver_data_block_free2(&p_sys->rist_items[i]);
-        }
+    for (size_t i = 0; i < i_rist_items_index; i++) {
+        rist_receiver_data_block_free2(&p_sys->rist_items[i]);
     }
     return NULL;
 }


=====================================
modules/access/rist.h
=====================================
@@ -29,6 +29,7 @@
 
 #include <vlc_common.h>
 #include <librist/librist.h>
+#include <limits.h>
 
 /* RIST max fifo count (private RIST_DATAOUT_QUEUE_BUFFERS in librist) */
 #define RIST_MAX_QUEUE_BUFFERS (1024)
@@ -141,13 +142,38 @@ static inline int rist_get_max_packet_size(vlc_object_t *p_this)
 
 static inline bool rist_add_peers(vlc_object_t *p_this, struct rist_ctx *ctx, char *psz_url, int i_multipeer_mode, int virt_dst_port, int i_recovery_length)
 {
-
-
     int i_rist_reorder_buffer = var_InheritInteger( p_this, RIST_CFG_PREFIX RIST_URL_PARAM_REORDER_BUFFER );
     int i_rist_retry_interval = var_InheritInteger( p_this, RIST_CFG_PREFIX RIST_CFG_RETRY_INTERVAL );
     int i_rist_max_retries = var_InheritInteger( p_this, RIST_CFG_PREFIX RIST_CFG_MAX_RETRIES );
     int i_rist_max_bitrate = var_InheritInteger(p_this, RIST_CFG_PREFIX RIST_URL_PARAM_BANDWIDTH);
 
+    if (i_recovery_length < 0) {
+        msg_Warn( p_this, "ignoring negative recovery length %d", i_recovery_length );
+        i_recovery_length = 0;
+    }
+    if (i_rist_reorder_buffer < 0) {
+        msg_Warn( p_this, "ignoring negative reorder buffer %d", i_rist_reorder_buffer );
+        i_rist_reorder_buffer = 0;
+    }
+    if (i_rist_retry_interval < 0) {
+        msg_Warn( p_this, "ignoring negative retry interval %d", i_rist_retry_interval );
+        i_rist_retry_interval = 0;
+    } else if (i_rist_retry_interval > INT_MAX / 10) {
+        i_rist_retry_interval = INT_MAX / 10;
+    }
+    if (i_rist_max_retries < 0) {
+        msg_Warn( p_this, "ignoring negative max retries %d", i_rist_max_retries );
+        i_rist_max_retries = 0;
+    }
+    if (i_rist_max_bitrate < 0) {
+        msg_Warn( p_this, "ignoring negative max bitrate %d", i_rist_max_bitrate );
+        i_rist_max_bitrate = 0;
+    }
+    if (i_multipeer_mode < 0) {
+        msg_Warn( p_this, "ignoring negative multipeer mode %d", i_multipeer_mode );
+        i_multipeer_mode = 0;
+    }
+
     char *psz_stream_name = NULL;
     psz_stream_name = var_InheritString( p_this, RIST_CFG_PREFIX RIST_URL_PARAM_CNAME );
 
@@ -166,7 +192,7 @@ static inline bool rist_add_peers(vlc_object_t *p_this, struct rist_ctx *ctx, ch
     msg_Info( p_this, "Setting retry buffer to %d ms", i_recovery_length );
 
     char *addr[] = {
-        strdup(psz_url),
+        psz_url ? strdup(psz_url) : NULL,
         var_InheritString( p_this, RIST_CFG_PREFIX RIST_CFG_URL2 ),
         var_InheritString( p_this, RIST_CFG_PREFIX RIST_CFG_URL3 ),
         var_InheritString( p_this, RIST_CFG_PREFIX RIST_CFG_URL4 )
@@ -192,7 +218,7 @@ static inline bool rist_add_peers(vlc_object_t *p_this, struct rist_ctx *ctx, ch
             .recovery_length_max = (uint32_t)i_recovery_length,
             .recovery_reorder_buffer = (uint32_t)i_rist_reorder_buffer,
             .recovery_rtt_min = (uint32_t)i_rist_retry_interval,
-            .recovery_rtt_max = (uint32_t)10*i_rist_retry_interval,
+            .recovery_rtt_max = (uint32_t)(10 * i_rist_retry_interval),
             .weight = (uint32_t)i_multipeer_mode,
             .congestion_control_mode = RIST_CONGESTION_CONTROL_MODE_NORMAL,
             .min_retries = 6,



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/35b498c5f0e35622299798b7beb344c944c24630

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/35b498c5f0e35622299798b7beb344c944c24630
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list