Fix out of bound issue for 'signature_info' array 06/239006/6
authorjiyong.min <jiyong.min@samsung.com>
Tue, 21 Jul 2020 04:29:11 +0000 (13:29 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Tue, 21 Jul 2020 22:47:07 +0000 (07:47 +0900)
  - #IMG_CODEC_UNKNOWN_TYPE is larger than the size of 'signature_info' array.
    Because mm_util_img_codec_type increases sequentially no longer,
    we can't use '_type' for loop of 'signature_info' array.
    The size of 'signature_info' and index for loop have been added.

Change-Id: I2196238e83a78c397d59be8187f46cce221c860b

magick/mm_util_info.c
packaging/libmm-utility.spec

index fc1da21..1c5f233 100644 (file)
@@ -34,6 +34,7 @@
 #define                READ_BMP_SIZE           14
 
 typedef struct {
+       mm_util_img_codec_type type;
        unsigned char *signature;
        unsigned int len;
        unsigned int offset;
@@ -46,12 +47,13 @@ static unsigned char gIfegBMPHeader[] = { 0x42, 0x4D };
 static unsigned char gIfegWBMPHeader[] = { 0x00, 0x00 };
 
 static const image_signature_t signature_info[] = {
-       { gIfegJPEGHeader, 2, 0},
-       { gIfegPNGHeader, 8, 0},
-       { gIfegGIFHeader, 3, 0},
-       { gIfegBMPHeader, 2, 0},
-       { gIfegWBMPHeader, 2, 0}
+       { IMG_CODEC_JPEG, gIfegJPEGHeader, 2, 0},
+       { IMG_CODEC_PNG, gIfegPNGHeader, 8, 0},
+       { IMG_CODEC_GIF, gIfegGIFHeader, 3, 0},
+       { IMG_CODEC_BMP, gIfegBMPHeader, 2, 0},
+       { IMG_CODEC_WBMP, gIfegWBMPHeader, 2, 0}
 };
+static const unsigned int signature_info_num = sizeof(signature_info) / sizeof(image_signature_t);
 
 static unsigned int __ReadBE16bitsToUINT(const unsigned char *pBuffer)
 {
@@ -264,7 +266,8 @@ static int __mm_util_get_image_info(const char *path, mm_util_img_codec_type *ty
        long file_size = 0;
        unsigned char data[MINIMUM_HEADER_BYTES] = {0, };
        size_t file_read = 0;
-       unsigned int _type = 0, _width = 0, _height = 0;
+       unsigned int idx = 0, _width = 0, _height = 0;
+       mm_util_img_codec_type _type = IMG_CODEC_UNKNOWN_TYPE;
 
        mm_util_retvm_if(!path, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid path");
 
@@ -287,8 +290,9 @@ static int __mm_util_get_image_info(const char *path, mm_util_img_codec_type *ty
        file_size -= MINIMUM_HEADER_BYTES;
 
        // get codec type using signature
-       for (_type = 0; _type < IMG_CODEC_UNKNOWN_TYPE; _type++) {
-               if (memcmp(data + signature_info[_type].offset, signature_info[_type].signature, signature_info[_type].len) == 0) {
+       for (idx = 0; idx < signature_info_num; idx++) {
+               if (memcmp(data + signature_info[idx].offset, signature_info[idx].signature, signature_info[idx].len) == 0) {
+                       _type = signature_info[idx].type;
                        mm_util_debug("type = %u", _type);
                        break;
                }
index ecec26d..72f7546 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.2.0
+Version:    0.2.1
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0