From: jiyong.min Date: Thu, 29 Aug 2019 05:18:45 +0000 (+0900) Subject: Fix coverity issue X-Git-Tag: accepted/tizen/unified/20190901.225914~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F82%2F212982%2F3;p=platform%2Fcore%2Fapi%2Fimage-util.git Fix coverity issue - Out-of-bounds issue to read image_format_mimetype_table - 'MM_UTIL_COLOR_NUM' is larger than array_size but the array can access with array_size(table_size). : So 'MM_UTIL_COLOR_NUM' is replaced to real array_size. Change-Id: I7804cd4d510499b46d96183a1afc918fc0ffc444 --- diff --git a/src/image_util_private.c b/src/image_util_private.c index d8f7b9e..1d5f883 100755 --- a/src/image_util_private.c +++ b/src/image_util_private.c @@ -32,7 +32,7 @@ typedef struct { const char *mimetype_name; } image_format_mimetype_pair_s; -static const image_format_mimetype_pair_s image_format_mimetype_table[MM_UTIL_COLOR_NUM] = { +static const image_format_mimetype_pair_s image_format_mimetype_table[] = { { MM_UTIL_COLOR_YUV420, MEDIA_FORMAT_YV12, "MEDIA_FORMAT_YV12" }, { MM_UTIL_COLOR_YUV422, MEDIA_FORMAT_422P, "MEDIA_FORMAT_422P" }, { MM_UTIL_COLOR_I420, MEDIA_FORMAT_I420, "MEDIA_FORMAT_I420" }, @@ -50,6 +50,8 @@ static const image_format_mimetype_pair_s image_format_mimetype_table[MM_UTIL_CO { MM_UTIL_COLOR_NV61, -1, "Not support" } }; +static const unsigned int image_format_mimetype_table_size = sizeof(image_format_mimetype_table) / sizeof(image_format_mimetype_pair_s); + static int _convert_colorspace_tbl[] = { MM_UTIL_COLOR_YUV420, /* IMAGE_UTIL_COLORSPACE_YUV420 */ MM_UTIL_COLOR_YUV422, /* IMAGE_UTIL_COLORSPACE_YUV422 */ @@ -273,15 +275,16 @@ static media_format_mimetype_e __image_format_to_mimetype(mm_util_color_format_e { unsigned int i = 0; - for (i = 0; i < MM_UTIL_COLOR_NUM; i++) { + for (i = 0; i < image_format_mimetype_table_size; i++) { if (image_format_mimetype_table[i].image_format == format) { image_util_debug("imgp fmt: %d mimetype fmt: %s", format, image_format_mimetype_table[i].mimetype_name); return image_format_mimetype_table[i].mimetype; } } - image_util_error("imgp fmt: %d", format); + image_util_error("not supported image format: %d", format); + /* if format can't be changed to mimetype, return max */ return MEDIA_FORMAT_MAX; } @@ -289,15 +292,17 @@ static mm_util_color_format_e __mimetype_to_image_format(media_format_mimetype_e { unsigned int i = 0; - for (i = 0; i < MM_UTIL_COLOR_NUM; i++) { + for (i = 0; i < image_format_mimetype_table_size; i++) { if (image_format_mimetype_table[i].mimetype == mimetype) { - image_util_debug("mimetype: %s imgp fmt: %d", image_format_mimetype_table[i].mimetype_name, image_format_mimetype_table[i].image_format); + image_util_debug("mimetype: %s imgp fmt: %d", image_format_mimetype_table[i].mimetype_name, + image_format_mimetype_table[i].image_format); return image_format_mimetype_table[i].image_format; } } - image_util_error("mimetype: %s", image_format_mimetype_table[i].mimetype_name); + image_util_error("not supported mimetype: %d", mimetype); + /* if mimetype can't be changed to image format, return max */ return MM_UTIL_COLOR_NUM; }