From: Jiyong Min Date: Mon, 17 Jul 2017 01:17:42 +0000 (+0900) Subject: Modify data type for the size of memory(buffer) from 'int' to 'unsigned int' X-Git-Tag: submit/tizen/20170719.012528^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6c4e77cecec7d5333503d80c20be2d413abbf049;p=platform%2Fcore%2Fmultimedia%2Flibmm-utility.git Modify data type for the size of memory(buffer) from 'int' to 'unsigned int' (Added to fix svace issue in imgp) Change-Id: Ic71248e05d76beb68b57885692747c3297f1abf2 Signed-off-by: Jiyong Min --- diff --git a/imgp/include/mm_util_imgp_internal.h b/imgp/include/mm_util_imgp_internal.h index 0855498..63b12ee 100755 --- a/imgp/include/mm_util_imgp_internal.h +++ b/imgp/include/mm_util_imgp_internal.h @@ -73,6 +73,8 @@ #define ALIGN_TO_8KB(x) ((((x) + (1 << 13) - 1) >> 13) << 13) #define ALIGN_TO_64KB(x) ((((x) + (1 << 16) - 1) >> 16) << 16) +#define SAFE_STRCPY(dst, src, n) g_strlcpy(dst, src, n) + /** * Image Process Info for dlopen */ diff --git a/imgp/mm_util_imgp.c b/imgp/mm_util_imgp.c index 4dbce09..befb447 100755 --- a/imgp/mm_util_imgp.c +++ b/imgp/mm_util_imgp.c @@ -482,23 +482,25 @@ static int __mm_set_format_label(imgp_info_s *_imgp_info_s, mm_util_img_format s } if (src_fmt_lable && dst_fmt_lable) { + unsigned int src_fmt_len = strlen(src_fmt_lable) + 1; + unsigned int dst_fmt_len = strlen(dst_fmt_lable) + 1; mm_util_debug("src_fmt_lable: %s dst_fmt_lable: %s", src_fmt_lable, dst_fmt_lable); - _imgp_info_s->input_format_label = (char *)malloc(strlen(src_fmt_lable) + 1); + _imgp_info_s->input_format_label = (char *)malloc(src_fmt_len); if (_imgp_info_s->input_format_label == NULL) { mm_util_error("[input] input_format_label is null"); return MM_UTIL_ERROR_OUT_OF_MEMORY; } - memset(_imgp_info_s->input_format_label, 0, strlen(src_fmt_lable) + 1); - strncpy(_imgp_info_s->input_format_label, src_fmt_lable, strlen(src_fmt_lable)); + memset(_imgp_info_s->input_format_label, 0, src_fmt_len); + SAFE_STRCPY(_imgp_info_s->input_format_label, src_fmt_lable, src_fmt_len); - _imgp_info_s->output_format_label = (char *)malloc(strlen(dst_fmt_lable) + 1); + _imgp_info_s->output_format_label = (char *)malloc(dst_fmt_len); if (_imgp_info_s->output_format_label == NULL) { mm_util_error("[input] input_format_label is null"); IMGP_FREE(_imgp_info_s->input_format_label); return MM_UTIL_ERROR_OUT_OF_MEMORY; } - memset(_imgp_info_s->output_format_label, 0, strlen(dst_fmt_lable) + 1); - strncpy(_imgp_info_s->output_format_label, dst_fmt_lable, strlen(dst_fmt_lable)); + memset(_imgp_info_s->output_format_label, 0, dst_fmt_len); + SAFE_STRCPY(_imgp_info_s->output_format_label, dst_fmt_lable, dst_fmt_len); mm_util_debug("input_format_label: %s output_format_label: %s", _imgp_info_s->input_format_label, _imgp_info_s->output_format_label); } else { diff --git a/jpeg/include/mm_util_jpeg.h b/jpeg/include/mm_util_jpeg.h index 863d2b9..7943d66 100755 --- a/jpeg/include/mm_util_jpeg.h +++ b/jpeg/include/mm_util_jpeg.h @@ -79,7 +79,7 @@ typedef struct mm_util_jpeg_yuv_format format; /**< pixel format*/ int width; /**< width */ int height; /**< heigt */ - int size; /**< size */ + unsigned int size; /**< size */ void *data; /**< data */ // int decode_yuv_subsample; /**< decode_yuv_subsample */ } mm_util_jpeg_yuv_data; @@ -117,7 +117,7 @@ int mm_util_jpeg_encode_to_file (const char *filename, void *src, int width, int * @see mm_util_jpeg_yuv_format * @since R1, 1.0 */ -int mm_util_jpeg_encode_to_memory (void **mem, int *size, void *src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality); +int mm_util_jpeg_encode_to_memory (void **mem, unsigned int *size, void *src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality); /** @@ -148,7 +148,7 @@ int mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *fi * @see mm_util_jpeg_yuv_data, mm_util_jpeg_yuv_format * @since R1, 1.0 */ -int mm_util_decode_from_jpeg_memory (mm_util_jpeg_yuv_data *decoded, void *src, int size, mm_util_jpeg_yuv_format fmt); +int mm_util_decode_from_jpeg_memory (mm_util_jpeg_yuv_data *decoded, void *src, unsigned int size, mm_util_jpeg_yuv_format fmt); /** * This function extracts yuv data from jpeg file with downscale decode option @@ -179,7 +179,7 @@ int mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, * @see mm_util_jpeg_yuv_data, mm_util_jpeg_yuv_format * @since R1, 1.0 */ -int mm_util_decode_from_jpeg_memory_with_downscale (mm_util_jpeg_yuv_data *decoded, void *src, int size, mm_util_jpeg_yuv_format fmt, mm_util_jpeg_decode_downscale downscale); +int mm_util_decode_from_jpeg_memory_with_downscale (mm_util_jpeg_yuv_data *decoded, void *src, unsigned int size, mm_util_jpeg_yuv_format fmt, mm_util_jpeg_decode_downscale downscale); #ifdef __cplusplus diff --git a/jpeg/mm_util_jpeg.c b/jpeg/mm_util_jpeg.c index e1f9614..553ea0b 100755 --- a/jpeg/mm_util_jpeg.c +++ b/jpeg/mm_util_jpeg.c @@ -287,7 +287,7 @@ static int __mm_image_decode_from_jpeg_file_with_libjpeg_turbo(mm_util_jpeg_yuv_ return iErrorCode; } -static int __mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(mm_util_jpeg_yuv_data *decoded_data, void *src, int size, mm_util_jpeg_yuv_format input_fmt) +static int __mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(mm_util_jpeg_yuv_data *decoded_data, void *src, unsigned int size, mm_util_jpeg_yuv_format input_fmt) { int iErrorCode = MM_UTIL_ERROR_NONE; tjhandle dhandle = NULL; @@ -306,7 +306,7 @@ static int __mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(mm_util_jpeg_yu return MM_UTIL_ERROR_OUT_OF_MEMORY; } - mm_util_debug("srcBuf[0]: 0x%2x, srcBuf[1]: 0x%2x, jpegSize:%d", srcBuf[0], srcBuf[1], size); + mm_util_debug("srcBuf[0]: 0x%2x, srcBuf[1]: 0x%2x, jpegSize:%u", srcBuf[0], srcBuf[1], size); __mm_decode_libjpeg_turbo_decompress(dhandle, src, size, TD_BU, decoded_data, input_fmt); if (dhandle) @@ -392,7 +392,7 @@ static int __mm_image_encode_to_jpeg_file_with_libjpeg_turbo(const char *filenam return MM_UTIL_ERROR_INVALID_PARAMETER; } _mm_encode_libjpeg_turbo_compress(chandle, src, &dstBuf, &size, width, height, quality, TD_BU, fmt); - mm_util_debug("dstBuf: %p\t size: %d", dstBuf, size); + mm_util_debug("dstBuf: %p\t size: %u", dstBuf, size); fwrite(dstBuf, 1, size, fout); fclose(fout); if (chandle) @@ -403,7 +403,7 @@ static int __mm_image_encode_to_jpeg_file_with_libjpeg_turbo(const char *filenam return iErrorCode; } -static int __mm_image_encode_to_jpeg_memory_with_libjpeg_turbo(void **mem, int *csize, void *rawdata, int w, int h, mm_util_jpeg_yuv_format fmt, int quality) +static int __mm_image_encode_to_jpeg_memory_with_libjpeg_turbo(void **mem, unsigned int *csize, void *rawdata, int w, int h, mm_util_jpeg_yuv_format fmt, int quality) { int iErrorCode = MM_UTIL_ERROR_NONE; tjhandle chandle = NULL; @@ -411,9 +411,9 @@ static int __mm_image_encode_to_jpeg_memory_with_libjpeg_turbo(void **mem, int * *csize = TJBUFSIZE(w, h); if (fmt == MM_UTIL_JPEG_FMT_RGB888) { - mm_util_debug("MM_UTIL_JPEG_FMT_RGB888 size: %d", *csize); + mm_util_debug("MM_UTIL_JPEG_FMT_RGB888 size: %u", *csize); } else if (fmt == MM_UTIL_JPEG_FMT_YUV420 || fmt == MM_UTIL_JPEG_FMT_YUV422) { - mm_util_debug("TJSAMP_420 ||TJSAMP_422 size: %d", *csize); + mm_util_debug("TJSAMP_420 ||TJSAMP_422 size: %u", *csize); } else { mm_util_error("We can't support the IMAGE format"); return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; @@ -430,9 +430,9 @@ static int __mm_image_encode_to_jpeg_memory_with_libjpeg_turbo(void **mem, int * return MM_UTIL_ERROR_INVALID_PARAMETER; } - mm_util_debug("width: %d height: %d, size: %d", w, h, *csize); + mm_util_debug("width: %d height: %d, size: %u", w, h, *csize); _mm_encode_libjpeg_turbo_compress(chandle, rawdata, (unsigned char **)mem, (unsigned long *)csize, w, h, quality, TD_BU, fmt); - mm_util_debug("dstBuf: %p &dstBuf:%p size: %d", *mem, mem, *csize); + mm_util_debug("dstBuf: %p &dstBuf:%p size: %u", *mem, mem, *csize); if (chandle) tjDestroy(chandle); return iErrorCode; @@ -676,7 +676,7 @@ static int __mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, vo return iErrorCode; } -static int __mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdata, int width, int height, mm_util_jpeg_yuv_format fmt, int quality) +static int __mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, unsigned int *csize, void *rawdata, int width, int height, mm_util_jpeg_yuv_format fmt, int quality) { int iErrorCode = MM_UTIL_ERROR_NONE; @@ -808,7 +808,7 @@ static int __mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, jpeg_finish_compress(&cinfo); mm_util_debug("jpeg_finish_compress"); jpeg_destroy_compress(&cinfo); - mm_util_debug("Exit jpeg_destroy_compress, mem: %p\t size:%d", *mem, *csize); + mm_util_debug("Exit jpeg_destroy_compress, mem: %p\t size:%u", *mem, *csize); } else if (fmt == MM_UTIL_JPEG_FMT_RGB888 || fmt == MM_UTIL_JPEG_FMT_GraySacle || fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) { @@ -867,7 +867,7 @@ static int __mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, mm_util_error("We can't encode the IMAGE format"); return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; } - *csize = (int)size; + *csize = (unsigned int)size; return iErrorCode; } @@ -1061,7 +1061,7 @@ static int __mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * return iErrorCode; } -static int __mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data *decoded_data, void *src, int size, mm_util_jpeg_yuv_format input_fmt, mm_util_jpeg_decode_downscale downscale) +static int __mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data *decoded_data, void *src, unsigned int size, mm_util_jpeg_yuv_format input_fmt, mm_util_jpeg_decode_downscale downscale) { int iErrorCode = MM_UTIL_ERROR_NONE; struct jpeg_decompress_struct dinfo; @@ -1306,7 +1306,7 @@ EXPORT_API int mm_util_jpeg_encode_to_file(const char *filename, void* src, int return ret; } -EXPORT_API int mm_util_jpeg_encode_to_memory(void **mem, int *size, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality) +EXPORT_API int mm_util_jpeg_encode_to_memory(void **mem, unsigned int *size, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality) { int ret = MM_UTIL_ERROR_NONE; @@ -1407,7 +1407,7 @@ EXPORT_API int mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, con #if LIBJPEG_TURBO mm_util_debug("#START# LIBJPEG_TURBO"); ret = __mm_image_decode_from_jpeg_file_with_libjpeg_turbo(decoded, filename, fmt); - mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size); + mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %u\n", decoded->data, decoded->width, decoded->height, decoded->size); mm_util_debug("#End# LIBJPEG_TURBO, Success!! ret: %d", ret); #else mm_util_debug("#START# libjpeg"); @@ -1445,7 +1445,7 @@ EXPORT_API int mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, con ret = __mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, fmt, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1); } - mm_util_debug("decoded->data: %p\t width: %d\t height:%d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size); + mm_util_debug("decoded->data: %p\t width: %d\t height:%d\t size: %u\n", decoded->data, decoded->width, decoded->height, decoded->size); mm_util_debug("#End# libjpeg, Success!! ret: %d", ret); #endif } else if (magic[0] == 0x47 && magic[1] == 0x49) { @@ -1466,7 +1466,7 @@ EXPORT_API int mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, con return ret; } -EXPORT_API int mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data *decoded, void *src, int size, mm_util_jpeg_yuv_format fmt) +EXPORT_API int mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data *decoded, void *src, unsigned int size, mm_util_jpeg_yuv_format fmt) { int ret = MM_UTIL_ERROR_NONE; @@ -1478,12 +1478,6 @@ EXPORT_API int mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data *decoded, v return MM_UTIL_ERROR_INVALID_PARAMETER; } - if (size < 0) { - mm_util_error("#ERROR# size"); - TTRACE_END(); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } - if ((fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888)) { mm_util_error("#ERROR# fmt value"); TTRACE_END(); @@ -1494,7 +1488,7 @@ EXPORT_API int mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data *decoded, v mm_util_debug("#START# libjpeg"); ret = __mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(decoded, src, size, fmt); - mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size); + mm_util_debug("decoded->data: %p\t width: %d\t height: %u\t size: %u\n", decoded->data, decoded->width, decoded->height, decoded->size); mm_util_debug("#END# libjpeg, Success!! ret: %d", ret); #else @@ -1534,7 +1528,7 @@ EXPORT_API int mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data *decoded, v ret = __mm_image_decode_from_jpeg_memory_with_libjpeg(decoded, src, size, fmt, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1); } - mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size); + mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %u\n", decoded->data, decoded->width, decoded->height, decoded->size); mm_util_debug("#END# libjpeg, Success!! ret: %d", ret); #endif @@ -1587,7 +1581,7 @@ EXPORT_API int mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_dat #if LIBJPEG_TURBO mm_util_debug("#START# LIBJPEG_TURBO"); ret = __mm_image_decode_from_jpeg_file_with_libjpeg_turbo(decoded, filename, fmt); - mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size); + mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %u\n", decoded->data, decoded->width, decoded->height, decoded->size); mm_util_debug("#End# LIBJPEG_TURBO, Success!! ret: %d", ret); #else mm_util_debug("#START# libjpeg"); @@ -1625,7 +1619,7 @@ EXPORT_API int mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_dat ret = __mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, fmt, downscale); } - mm_util_debug("decoded->data: %p\t width: %d\t height:%d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size); + mm_util_debug("decoded->data: %p\t width: %d\t height:%d\t size: %u\n", decoded->data, decoded->width, decoded->height, decoded->size); mm_util_debug("#End# libjpeg, Success!! ret: %d", ret); #endif } else if (magic[0] == 0x47 && magic[1] == 0x49) { @@ -1646,7 +1640,7 @@ EXPORT_API int mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_dat return ret; } -EXPORT_API int mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_data *decoded, void *src, int size, mm_util_jpeg_yuv_format fmt, mm_util_jpeg_decode_downscale downscale) +EXPORT_API int mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_data *decoded, void *src, unsigned int size, mm_util_jpeg_yuv_format fmt, mm_util_jpeg_decode_downscale downscale) { int ret = MM_UTIL_ERROR_NONE; @@ -1658,12 +1652,6 @@ EXPORT_API int mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_d return MM_UTIL_ERROR_INVALID_PARAMETER; } - if (size < 0) { - mm_util_error("#ERROR# size"); - TTRACE_END(); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } - if ((fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888)) { mm_util_error("#ERROR# fmt value"); TTRACE_END(); @@ -1681,7 +1669,7 @@ EXPORT_API int mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_d mm_util_debug("#START# libjpeg"); ret = __mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(decoded, src, size, fmt); - mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size); + mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %u\n", decoded->data, decoded->width, decoded->height, decoded->size); mm_util_debug("#END# libjpeg, Success!! ret: %d", ret); #else @@ -1721,7 +1709,7 @@ EXPORT_API int mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_d ret = __mm_image_decode_from_jpeg_memory_with_libjpeg(decoded, src, size, fmt, downscale); } - mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size); + mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %u\n", decoded->data, decoded->width, decoded->height, decoded->size); mm_util_debug("#END# libjpeg, Success!! ret: %d", ret); #endif diff --git a/jpeg/test/mm_util_jpeg_testsuite.c b/jpeg/test/mm_util_jpeg_testsuite.c index 38eb5ef..75cf6fc 100755 --- a/jpeg/test/mm_util_jpeg_testsuite.c +++ b/jpeg/test/mm_util_jpeg_testsuite.c @@ -43,7 +43,7 @@ static inline void flush_stdin() } -static int _read_file(char *file_name, void **data, int *data_size) +static int _read_file(char *file_name, void **data, unsigned int *data_size) { FILE *fp = NULL; long file_size = 0; @@ -85,7 +85,7 @@ static int _read_file(char *file_name, void **data, int *data_size) fp = NULL; if (*data) { - *data_size = file_size; + *data_size = (unsigned int)file_size; return TRUE; } else { *data_size = 0; @@ -100,12 +100,12 @@ static int _read_file(char *file_name, void **data, int *data_size) } -static int _write_file(const char *file_name, void *data, int data_size) +static int _write_file(const char *file_name, void *data, unsigned int data_size) { FILE *fp = NULL; - if (!file_name || !data || data_size <= 0) { - fprintf(stderr, "\tinvalid data %s %p size:%d\n", file_name, data, data_size); + if (!file_name || !data || data_size == 0) { + fprintf(stderr, "\tinvalid data %s %p size:%u\n", file_name, data, data_size); return FALSE; } @@ -130,8 +130,8 @@ static int _write_file(const char *file_name, void *data, int data_size) int main(int argc, char *argv[]) { int ret = 0; - int src_size = 0; - int dst_size = 0; + unsigned int src_size = 0; + unsigned int dst_size = 0; int width = 0; int height = 0; int quality = 0; @@ -207,7 +207,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "\tJPEG OPERATION SUCCESS\n"); if (!strcmp("encode", argv[1])) { if (dst) { - fprintf(stderr, "\t##Encoded data##: %p\tsize: %d\n", dst, dst_size); + fprintf(stderr, "\t##Encoded data##: %p\tsize: %u\n", dst, dst_size); _write_file(ENCODE_RESULT_PATH, dst, dst_size); diff --git a/packaging/libmm-utility.spec b/packaging/libmm-utility.spec index 8071b7d..2882b4e 100755 --- a/packaging/libmm-utility.spec +++ b/packaging/libmm-utility.spec @@ -1,6 +1,6 @@ Name: libmm-utility Summary: Multimedia Framework Utility Library -Version: 0.32 +Version: 0.33 Release: 0 Group: System/Libraries License: Apache-2.0