Prevent unintentional progress 75/306475/2
authorminje.ahn <minje.ahn@samsung.com>
Thu, 22 Feb 2024 01:54:58 +0000 (10:54 +0900)
committerminje.ahn <minje.ahn@samsung.com>
Thu, 22 Feb 2024 05:19:53 +0000 (14:19 +0900)
[issue]
If 'option' is NULL, JPEG definition is added regardless of the file type.

[fix]
Add 'option' checker.

Change-Id: Ib0d143a27e50d3a363fb4385c225fd280b69be6f
Signed-off-by: minje.ahn <minje.ahn@samsung.com>
magick/mm_util_magick.c

index 4ae4167..63cd05a 100644 (file)
@@ -346,7 +346,6 @@ static int __mm_util_write_image_to_file(Image *image, mm_util_enc_opt_t *option
        int ret = MM_UTIL_ERROR_NONE;
        ImageInfo *_image_info = NULL;
        ExceptionInfo exception;
-       mm_util_img_codec_type codec = IMG_CODEC_JPEG;
 
        mm_util_fenter();
 
@@ -369,38 +368,37 @@ static int __mm_util_write_image_to_file(Image *image, mm_util_enc_opt_t *option
        DeleteImageProfile(image, "IPTC");
        DeleteImageProfile(image, "XMP");
 
-       if (option)
-               codec = option->codec;
-
-       switch (codec) {
-       case IMG_CODEC_JPEG:
-               AddDefinition(_image_info, "jpeg", "dct-method", "FASTEST", &exception);
-               AddDefinition(_image_info, "jpeg", "optimize-coding", "FALSE", &exception);
-               break;
-
-       case IMG_CODEC_PNG:
-               mm_util_sec_debug("PNG compression: %d", option->compression);
-               _image_info->quality = option->compression * 10;
-               break;
-
-       case IMG_CODEC_WEBP:
-               mm_util_sec_debug("WEBP lossless: %s", (option->lossless ? "TRUE" : "FALSE"));
-               AddDefinition(_image_info, "webp", "lossless", (option->lossless ? "TRUE" : "FALSE"), &exception);
-               break;
-
-       case IMG_CODEC_GIF:
-               /* fall through */
-       case IMG_CODEC_BMP:
-               /* fall through */
-       case IMG_CODEC_WBMP:
-               break;
-
-       default:
-               mm_util_error("invalid codec [%d]", codec);
-               break;
+       if (option) {
+               switch (option->codec) {
+               case IMG_CODEC_JPEG:
+                       AddDefinition(_image_info, "jpeg", "dct-method", "FASTEST", &exception);
+                       AddDefinition(_image_info, "jpeg", "optimize-coding", "FALSE", &exception);
+                       break;
+
+               case IMG_CODEC_PNG:
+                       mm_util_sec_debug("PNG compression: %d", option->compression);
+                       _image_info->quality = option->compression * 10;
+                       break;
+
+               case IMG_CODEC_WEBP:
+                       mm_util_sec_debug("WEBP lossless: %s", (option->lossless ? "TRUE" : "FALSE"));
+                       AddDefinition(_image_info, "webp", "lossless", (option->lossless ? "TRUE" : "FALSE"), &exception);
+                       break;
+
+               case IMG_CODEC_GIF:
+                       /* fall through */
+               case IMG_CODEC_BMP:
+                       /* fall through */
+               case IMG_CODEC_WBMP:
+                       break;
+
+               default:
+                       mm_util_error("invalid codec [%d]", option->codec);
+                       break;
+               }
        }
 
-       if (WriteImage (_image_info, image) == MagickFalse) {
+       if (WriteImage(_image_info, image) == MagickFalse) {
                mm_util_error("Error: Writing Image failed.");
                if (exception.severity != UndefinedException)
                        CatchException(&exception);