]> git.sesse.net Git - mlt/commitdiff
Validate alpha channel size before cropping and padding it.
authorDan Dennedy <dan@dennedy.org>
Sat, 11 Sep 2010 05:08:44 +0000 (22:08 -0700)
committerDan Dennedy <dan@dennedy.org>
Sat, 11 Sep 2010 05:08:44 +0000 (22:08 -0700)
Eventually, I need to add mlt_frame_get_alpha() that returns a size and
mlt_frame_set_alpha() encapsulates handling of the alpha channel.

src/modules/core/filter_crop.c
src/modules/core/filter_resize.c

index 8edad23ca7327bb6f880932c7df844a2b104edc1..c6960cc2ed10f632e8ed64bc4f76fa6339d6eaa2 100644 (file)
@@ -127,7 +127,9 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
 
                // We should resize the alpha too
                uint8_t *alpha = mlt_frame_get_alpha_mask( this );
-               if ( alpha != NULL )
+               int alpha_size = 0;
+               mlt_properties_get_data( properties, "alpha", &alpha_size );
+               if ( alpha && alpha_size >= ( *width * *height ) )
                {
                        uint8_t *newalpha = mlt_pool_alloc( owidth * oheight );
                        if ( newalpha )
index 9efa5a1febeafe6150dd5e85b70906ce5eddcfb9..2d84b8f250f42ffd8cbdf3d8f4d342160161a010 100644 (file)
@@ -140,6 +140,8 @@ static uint8_t *frame_resize_image( mlt_frame this, int owidth, int oheight, int
        // Get the input image, width and height
        uint8_t *input = mlt_properties_get_data( properties, "image", NULL );
        uint8_t *alpha = mlt_frame_get_alpha_mask( this );
+       int alpha_size = 0;
+       mlt_properties_get_data( properties, "alpha", &alpha_size );
 
        int iwidth = mlt_properties_get_int( properties, "width" );
        int iheight = mlt_properties_get_int( properties, "height" );
@@ -161,11 +163,14 @@ static uint8_t *frame_resize_image( mlt_frame this, int owidth, int oheight, int
                mlt_properties_set_int( properties, "height", oheight );
 
                // We should resize the alpha too
-               alpha = resize_alpha( alpha, owidth, oheight, iwidth, iheight, alpha_value );
-               if ( alpha != NULL )
+               if ( alpha && alpha_size >= iwidth * iheight )
                {
-                       mlt_properties_set_data( properties, "alpha", alpha, owidth * oheight, ( mlt_destructor )mlt_pool_release, NULL );
-                       this->get_alpha_mask = NULL;
+                       alpha = resize_alpha( alpha, owidth, oheight, iwidth, iheight, alpha_value );
+                       if ( alpha )
+                       {
+                               mlt_properties_set_data( properties, "alpha", alpha, owidth * oheight, ( mlt_destructor )mlt_pool_release, NULL );
+                               this->get_alpha_mask = NULL;
+                       }
                }
 
                // Return the output