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

François Cartegnie (@fcartegnie) gitlab at videolan.org
Sat Sep 5 05:42:32 UTC 2026



François Cartegnie pushed to branch 3.0.x at VideoLAN / VLC


Commits:
4dddcefc by François Cartegnie at 2026-09-05T07:35:09+02:00
video_filter: gaussianblur: replace xmalloc and check alloc

(adapted from commit bbed282f603743ccf04160fce129d468bc9f2030)

- - - - -
d62ce2d2 by François Cartegnie at 2026-09-05T07:35:09+02:00
video_filter: gaussianblur: check for overflow

(adapted from commit 55639fd586becfecd658656e30daad6c638ad44c)

- - - - -


1 changed file:

- modules/video_filter/gaussianblur.c


Changes:

=====================================
modules/video_filter/gaussianblur.c
=====================================
@@ -37,6 +37,7 @@
 #include "filter_picture.h"
 
 #include <math.h>                                          /* exp(), sqrt() */
+#include <stdckdint.h>
 
 /*****************************************************************************
  * Module descriptor
@@ -103,11 +104,13 @@ struct filter_sys_t
     type_t *pt_scale;
 };
 
-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++ )
     {
@@ -123,6 +126,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( vlc_object_t *p_this )
@@ -165,7 +170,11 @@ static int Create( vlc_object_t *p_this )
         msg_Err( p_filter, "sigma must be greater than zero" );
         return VLC_EGENERIC;
     }
-    gaussianblur_InitDistribution( p_filter->p_sys );
+    if( gaussianblur_InitDistribution( p_filter->p_sys ) != VLC_SUCCESS )
+    {
+        free( p_filter->p_sys );
+        return VLC_ENOMEM;
+    }
     msg_Dbg( p_filter, "gaussian distribution is %d pixels wide",
              p_filter->p_sys->i_dim*2+1 );
 
@@ -197,29 +206,39 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
 
     if( !p_pic ) return NULL;
 
-    p_outpic = filter_NewPicture( p_filter );
-    if( !p_outpic )
+    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 ) ) )
     {
         picture_Release( p_pic );
         return NULL;
     }
+
     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 = malloc( i_y_plane_bytes );
+        if( !p_sys->pt_buffer )
+        {
+            picture_Release( p_pic );
+            return NULL;
+        }
     }
 
     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 )
+        {
+            picture_Release( p_pic );
+            return NULL;
+        }
+        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++ )
@@ -243,6 +262,13 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         }
     }
 
+    p_outpic = filter_NewPicture( p_filter );
+    if( !p_outpic )
+    {
+        picture_Release( p_pic );
+        return NULL;
+    }
+
     pt_scale = p_sys->pt_scale;
     for( int i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
     {



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f8304cd9c1addf5e059c0416d54f9d3ac2c48281...d62ce2d2d6bade49f4bb32fc09b1fef4d2f73827

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