]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8905 #resolve [Heap overflow in img patch]
authorAnthony Minessale <anthm@freeswitch.org>
Sat, 5 Mar 2016 20:41:38 +0000 (14:41 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Sat, 5 Mar 2016 20:41:38 +0000 (14:41 -0600)
src/include/switch_core_video.h
src/mod/formats/mod_local_stream/mod_local_stream.c
src/switch_core_video.c

index 0e9ebdd3201c3beb310227010b2dff7cf7549455..00b9de4175c86bb1e0867ad5cbb24f98d38bb30c 100644 (file)
@@ -330,9 +330,9 @@ SWITCH_DECLARE(void) switch_png_free(switch_png_t **pngP);
 * \param[in]    img       The small Image descriptor
 * \param[in]    x         Leftmost pos
 * \param[in]    y         Topmost pos
-* \param[in]    alpha     Alaha value from 0(completely transparent) to 255(opaque)
+* \param[in]    percent   Alaha value from 0(completely transparent) to 100(opaque)
 */
-SWITCH_DECLARE(void) switch_img_overlay(switch_image_t *IMG, switch_image_t *img, int x, int y, uint8_t alpha);
+SWITCH_DECLARE(void) switch_img_overlay(switch_image_t *IMG, switch_image_t *img, int x, int y, uint8_t percent);
 
 SWITCH_DECLARE(switch_status_t) switch_img_scale(switch_image_t *src, switch_image_t **destP, int width, int height);
 SWITCH_DECLARE(switch_status_t) switch_img_fit(switch_image_t **srcP, int width, int height, switch_img_fit_t fit);
index b704e8b83a1bfaa1859259a41ec89139e7b6f57f..df251283727d0f20c20556a725aec31a1500ec5b 100644 (file)
@@ -123,7 +123,8 @@ struct local_stream_source {
        switch_timer_t timer;
        int logo_always;
        switch_img_position_t logo_pos;
-       int logo_opacity;
+       uint8_t logo_opacity;
+       uint8_t text_opacity;
 };
 
 typedef struct local_stream_source local_stream_source_t;
@@ -1061,9 +1062,7 @@ static switch_status_t local_stream_file_read_video(switch_file_handle_t *handle
        }
 
        if (frame->img && context->banner_img && frame->img->d_w >= context->banner_img->d_w) {
-               //switch_img_overlay(frame->img, context->banner_img, 0, frame->img->d_h - context->banner_img->d_h, 100);
-               switch_img_patch(frame->img, context->banner_img, 0, frame->img->d_h - context->banner_img->d_h);
-               //switch_img_patch(frame->img, context->banner_img, 0, 0);
+               switch_img_overlay(frame->img, context->banner_img, 0, frame->img->d_h - context->banner_img->d_h, context->source->text_opacity);
        }
 
        if (frame->img && context->source->logo_img && 
@@ -1079,11 +1078,7 @@ static switch_status_t local_stream_file_read_video(switch_file_handle_t *handle
                        y -= context->banner_img->d_h;
                }
 
-               if (context->source->logo_opacity > 0 && context->source->logo_opacity < 100) {
-                       switch_img_overlay(frame->img, context->source->logo_img, x, y-1, context->source->logo_opacity);
-               } else {
-                       switch_img_patch(frame->img, context->source->logo_img, x, y-1);
-               }
+               switch_img_overlay(frame->img, context->source->logo_img, x, y, context->source->logo_opacity);
        }
 
        return SWITCH_STATUS_SUCCESS;
@@ -1156,6 +1151,8 @@ static void launch_thread(const char *name, const char *path, switch_xml_t direc
        source->stopped = 0;
        source->hup = 0;
        source->chime_freq = 30;
+       source->logo_opacity = source->text_opacity = 100;
+
        for (param = switch_xml_child(directory, "param"); param; param = param->next) {
                char *var = (char *) switch_xml_attr_soft(param, "name");
                char *val = (char *) switch_xml_attr_soft(param, "value");
@@ -1214,6 +1211,11 @@ static void launch_thread(const char *name, const char *path, switch_xml_t direc
                        if (source->logo_opacity < 0 && source->logo_opacity > 100) {
                                source->logo_opacity = 0;
                        }
+               } else if (!strcasecmp(var, "text-opacity") && !zstr(val)) {
+                       source->text_opacity = atoi(val);
+                       if (source->text_opacity < 0 && source->text_opacity > 100) {
+                               source->text_opacity = 0;
+                       }
                }
        }
 
index 67c2f7ae69fe19d75030c0129466787e363c975b..69bd310fd1d8f6cb046e652e9540285b0a89ade9 100644 (file)
@@ -580,11 +580,13 @@ static inline void switch_img_get_rgb_pixel(switch_image_t *img, switch_rgb_colo
 #endif 
 }
 
-SWITCH_DECLARE(void) switch_img_overlay(switch_image_t *IMG, switch_image_t *img, int x, int y, uint8_t alpha)
+SWITCH_DECLARE(void) switch_img_overlay(switch_image_t *IMG, switch_image_t *img, int x, int y, uint8_t percent)
 {
        int i, j, len, max_h;
        switch_rgb_color_t RGB = {0}, rgb = {0}, c = {0};
        int xoff = 0, yoff = 0;
+       uint8_t alpha = (int8_t)((255 * percent) / 100);
+
 
        switch_assert(IMG->fmt == SWITCH_IMG_FMT_I420);