[vlc-commits] [Git][videolan/vlc][master] 2 commits: video_filter: gaussianblur: replace xmalloc and check alloc

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Aug 18 07:49:15 UTC 2026



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
bbed282f by François Cartegnie at 2026-08-18T07:36:17+00:00
video_filter: gaussianblur: replace xmalloc and check alloc

- - - - -
55639fd5 by François Cartegnie at 2026-08-18T07:36:17+00:00
video_filter: gaussianblur: check for overflow

- - - - -


1 changed file:

- modules/video_filter/gaussianblur.c


Changes:

=====================================
modules/video_filter/gaussianblur.c
=====================================
@@ -36,6 +36,7 @@
 #include <vlc_picture.h>
 
 #include <math.h>                                          /* exp(), sqrt() */
+#include <stdckdint.h>
 
 /*****************************************************************************
  * Module descriptor
@@ -98,11 +99,13 @@ typedef struct
     type_t *pt_scale;
 } filter_sys_t;
 
-static void gaussianblur_InitDistribution( filter_sys_t *p_sys )
+static int gaussianblur_InitDistribution( filter_sys_t *p_sys )
 {
     double f_sigma = p_sys->f_sigma;
     int i_dim = (int)(3.*f_sigma);
-    type_t *pt_distribution = xmalloc( (2*i_dim+1) * sizeof( type_t ) );
+    type_t *pt_distribution = vlc_alloc( 2*i_dim+1, sizeof( type_t ) );
+    if( pt_distribution == NULL )
+        return VLC_ENOMEM;
 
     for( int x = -i_dim; x <= i_dim; x++ )
     {
@@ -118,6 +121,8 @@ static void gaussianblur_InitDistribution( filter_sys_t *p_sys )
     }
     p_sys->i_dim = i_dim;
     p_sys->pt_distribution = pt_distribution;
+
+    return VLC_SUCCESS;
 }
 
 static int Create( filter_t *p_filter )
@@ -158,7 +163,11 @@ static int Create( filter_t *p_filter )
         msg_Err( p_filter, "sigma must be greater than zero" );
         return VLC_EGENERIC;
     }
-    gaussianblur_InitDistribution( p_sys );
+    if( gaussianblur_InitDistribution( p_sys ) != VLC_SUCCESS )
+    {
+        free( p_sys );
+        return VLC_ENOMEM;
+    }
     msg_Dbg( p_filter, "gaussian distribution is %d pixels wide",
              p_sys->i_dim*2+1 );
 
@@ -187,23 +196,30 @@ static void Filter( filter_t *p_filter, picture_t *p_pic, picture_t *p_outpic )
     type_t *pt_scale;
     const type_t *pt_distribution = p_sys->pt_distribution;
 
+    size_t i_y_plane_bytes;
+    if( ckd_mul( &i_y_plane_bytes, p_pic->p[Y_PLANE].i_visible_lines, p_pic->p[Y_PLANE].i_pitch ) ||
+        ckd_mul( &i_y_plane_bytes, i_y_plane_bytes, sizeof( type_t ) ) )
+        return; // FIXME: nullify output ?
+
     if( !p_sys->pt_buffer )
     {
-        p_sys->pt_buffer = realloc_or_free( p_sys->pt_buffer,
-                               p_pic->p[Y_PLANE].i_visible_lines *
-                               p_pic->p[Y_PLANE].i_pitch * sizeof( type_t ) );
+        p_sys->pt_buffer = realloc_or_free( p_sys->pt_buffer, i_y_plane_bytes );
+        if( !p_sys->pt_buffer )
+            return;
     }
 
     pt_buffer = p_sys->pt_buffer;
     if( !p_sys->pt_scale )
     {
+        p_sys->pt_scale = malloc( i_y_plane_bytes );
+        if( !p_sys->pt_scale )
+            return;
+        pt_scale = p_sys->pt_scale;
+
         const int i_visible_lines = p_pic->p[Y_PLANE].i_visible_lines;
         const int i_visible_pitch = p_pic->p[Y_PLANE].i_visible_pitch;
         const int i_pitch = p_pic->p[Y_PLANE].i_pitch;
 
-        p_sys->pt_scale = xmalloc( i_visible_lines * i_pitch * sizeof( type_t ) );
-        pt_scale = p_sys->pt_scale;
-
         for( int i_line = 0; i_line < i_visible_lines; i_line++ )
         {
             for( int i_col = 0; i_col < i_visible_pitch; i_col++ )



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/fbe4f7f2870846e246e58ac4532340ff6129c268...55639fd586becfecd658656e30daad6c638ad44c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/fbe4f7f2870846e246e58ac4532340ff6129c268...55639fd586becfecd658656e30daad6c638ad44c
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