Add typecast to prevent overflow of arithmatic results 73/283073/3 accepted/tizen/unified/20221103.165756
authorjiyong.min <jiyong.min@samsung.com>
Tue, 18 Oct 2022 00:48:37 +0000 (09:48 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Wed, 19 Oct 2022 05:54:21 +0000 (14:54 +0900)
Change-Id: I5e465eebb8874eb4481769bd6232a713b7ed11de

gif/mm_util_gif.c
imgp/mm_util_imgp.c
jpeg/mm_util_jpeg.c
magick/mm_util_magick.c
packaging/libmm-utility.spec

index f635466..19c8a62 100644 (file)
@@ -390,7 +390,7 @@ static int __gif_make_color_map(mm_image_info_s *gif_image, ColorMapObject **col
        mm_util_retvm_if(!intermediate_image, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid intermediate_image");
        mm_util_retvm_if(!intermediate_image_size, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid intermediate_image_size");
 
-       num_of_pixels = gif_image->width * gif_image->height;
+       num_of_pixels = (unsigned long)(gif_image->width) * gif_image->height;
 
        if ((gif_color_map = GifMakeMapObject(colormap_size, NULL)) == NULL) {
                mm_util_error("failed to make color map");
@@ -512,7 +512,7 @@ static int __gif_image_write_image(gif_file_s *gif_file, mm_image_info_s *gif_im
        return ret;
 }
 
-static int __gif_image_create_ext_block(int function, int byte_count, ExtensionBlock **ext_block)
+static int __gif_image_create_ext_block(int function, unsigned int byte_count, ExtensionBlock **ext_block)
 {
        ExtensionBlock *_ext_block = NULL;
 
index 465487b..1dbcb1a 100644 (file)
@@ -92,8 +92,9 @@ static int __mm_util_get_image_size(mm_util_color_format_e format, unsigned int
 {
        unsigned char x_chroma_shift = 0;
        unsigned char y_chroma_shift = 0;
-       unsigned int w2, h2, stride, stride2;
+       size_t w2, h2, stride, stride2;
        size_t size, size2;
+       size_t _width = (size_t)width;
 
        mm_util_fenter();
 
@@ -106,10 +107,10 @@ static int __mm_util_get_image_size(mm_util_color_format_e format, unsigned int
        case MM_UTIL_COLOR_YUV420:
                x_chroma_shift = 1;
                y_chroma_shift = 1;
-               stride = MM_UTIL_ROUND_UP_4(width);
+               stride = MM_UTIL_ROUND_UP_4(_width);
                h2 = ROUND_UP_X(height, x_chroma_shift);
                size = stride * h2;
-               w2 = DIV_ROUND_UP_X(width, x_chroma_shift);
+               w2 = DIV_ROUND_UP_X(_width, x_chroma_shift);
                stride2 = MM_UTIL_ROUND_UP_4(w2);
                h2 = DIV_ROUND_UP_X(height, y_chroma_shift);
                size2 = stride2 * h2;
@@ -120,19 +121,19 @@ static int __mm_util_get_image_size(mm_util_color_format_e format, unsigned int
        case MM_UTIL_COLOR_UYVY:
        case MM_UTIL_COLOR_NV16:
        case MM_UTIL_COLOR_NV61:
-               stride = MM_UTIL_ROUND_UP_4(width) * 2;
+               stride = MM_UTIL_ROUND_UP_4(_width) * 2;
                size = stride * height;
                *imgsize = size;
                break;
 
        case MM_UTIL_COLOR_RGB16:
-               stride = 2 * (is_crop ? width : MM_UTIL_ROUND_UP_4(width));
+               stride = 2 * (is_crop ? _width : MM_UTIL_ROUND_UP_4(_width));
                size = stride * height;
                *imgsize = size;
                break;
 
        case MM_UTIL_COLOR_RGB24:
-               stride = 3 * (is_crop ? width : MM_UTIL_ROUND_UP_4(width));
+               stride = 3 * (is_crop ? _width : MM_UTIL_ROUND_UP_4(_width));
                size = stride * height;
                *imgsize = size;
                break;
@@ -141,7 +142,7 @@ static int __mm_util_get_image_size(mm_util_color_format_e format, unsigned int
        case MM_UTIL_COLOR_BGRA:
        case MM_UTIL_COLOR_RGBA:
        case MM_UTIL_COLOR_BGRX:
-               stride = width * 4;
+               stride = _width * 4;
                size = stride * height;
                *imgsize = size;
                break;
@@ -151,10 +152,10 @@ static int __mm_util_get_image_size(mm_util_color_format_e format, unsigned int
        case MM_UTIL_COLOR_NV21:
                x_chroma_shift = 1;
                y_chroma_shift = 1;
-               stride = MM_UTIL_ROUND_UP_4(width);
+               stride = MM_UTIL_ROUND_UP_4(_width);
                h2 = ROUND_UP_X(height, y_chroma_shift);
                size = stride * h2;
-               w2 = 2 * DIV_ROUND_UP_X(width, x_chroma_shift);
+               w2 = 2 * DIV_ROUND_UP_X(_width, x_chroma_shift);
                stride2 = MM_UTIL_ROUND_UP_4(w2);
                h2 = DIV_ROUND_UP_X(height, y_chroma_shift);
                size2 = stride2 * h2;
@@ -204,8 +205,8 @@ static void __mm_util_crop_rgb32(const unsigned char *src, unsigned int src_widt
 unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char *dst)
 {
        unsigned int idx = 0;
-       int src_bytesperline = src_width * 4;
-       int dst_bytesperline = crop_dest_width * 4;
+       unsigned long src_bytesperline = (unsigned long)src_width * 4;
+       unsigned long dst_bytesperline = (unsigned long)crop_dest_width * 4;
 
        src += crop_start_y * src_bytesperline + 4 * crop_start_x;
 
@@ -220,8 +221,8 @@ static void __mm_util_crop_rgb24(const unsigned char *src, unsigned int src_widt
 unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char *dst)
 {
        unsigned int idx = 0;
-       unsigned long src_bytesperline = src_width * 3;
-       unsigned long dst_bytesperline = crop_dest_width * 3;
+       unsigned long src_bytesperline = (unsigned long)src_width * 3;
+       unsigned long dst_bytesperline = (unsigned long)crop_dest_width * 3;
 
        src += crop_start_y * src_bytesperline + 3 * crop_start_x;
 
@@ -236,8 +237,8 @@ static void __mm_util_crop_rgb16(const unsigned char *src, unsigned int src_widt
 unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char *dst)
 {
        unsigned int idx = 0;
-       unsigned long src_bytesperline = src_width * 2;
-       unsigned long dst_bytesperline = crop_dest_width * 2;
+       unsigned long src_bytesperline = (unsigned long)src_width * 2;
+       unsigned long dst_bytesperline = (unsigned long)crop_dest_width * 2;
 
        src += crop_start_y * src_bytesperline + 2 * crop_start_x;
 
index 8b638d3..0e94589 100644 (file)
@@ -207,13 +207,13 @@ static int __jpeg_decode_get_buffer_size(j_decompress_ptr dinfo, unsigned int ro
        *size = 0;
 
        if (color_format == MM_UTIL_COLOR_RGB24 || color_format == MM_UTIL_COLOR_RGBA || color_format == MM_UTIL_COLOR_BGRA || color_format == MM_UTIL_COLOR_ARGB) {
-               *size = dinfo->output_height * row_stride;
+               *size = (size_t)(dinfo->output_height) * row_stride;
        } else if (color_format == MM_UTIL_COLOR_YUV420) {
-               *size = dinfo->output_height * row_stride / 2;
+               *size = (size_t)(dinfo->output_height) * row_stride / 2;
        } else if (color_format == MM_UTIL_COLOR_YUV422 || color_format == MM_UTIL_COLOR_UYVY) {
-               *size = dinfo->output_height * dinfo->output_width * 2;
+               *size = (size_t)(dinfo->output_height) * dinfo->output_width * 2;
        } else if (color_format == MM_UTIL_COLOR_GRAYSCALE) {
-               *size = dinfo->output_height * dinfo->output_width;
+               *size = (size_t)(dinfo->output_height) * dinfo->output_width;
        } else {
                mm_util_error("[%d] We can't decode the IMAGE format", color_format);
                return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
index 7b82284..b329105 100644 (file)
@@ -215,8 +215,8 @@ static int __mm_util_resize_image(Image *image, unsigned int width, unsigned int
        Image *_processed_image = NULL;
        Image *_sampled_image = NULL;
        ExceptionInfo exception;
-       unsigned int check_factor = 3;
-       unsigned int sample_factor = 2;
+       unsigned long check_factor = 3;
+       unsigned long sample_factor = 2;
 
        mm_util_fenter();
 
index 107c053..748d165 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.4.8
+Version:    0.4.9
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0