bug fix. improper use of negative value 17/259617/2
authorJiyong Min <jiyong.min@samsung.com>
Thu, 10 Jun 2021 07:58:27 +0000 (16:58 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Fri, 11 Jun 2021 01:22:55 +0000 (10:22 +0900)
  - fix coverity issue
  'av_image_get_buffer_size()' function can return negative value.
  So it is necessary to check negative value before using it.

Change-Id: I24fb99ffb49c1e9d0ae6185460b1c9fe8e0d1878

src/heif_decode_ffmpeg.c

index 1602f2e..22591ec 100644 (file)
@@ -73,6 +73,7 @@ static int __ffmpeg_get_image_from_frame(AVFrame *frame, heif_color_format_e col
        int dst_linesize[4];
        int pix_fmt = AV_PIX_FMT_NONE;
        heif_image_t *output;
+       int buffer_size = 0;
 
        heif_retvm_if_failed(frame, LIBHEIF_ERROR_INVALID_PARAMETER, "invalid frame");
        heif_retvm_if_failed(libav_output, LIBHEIF_ERROR_INVALID_PARAMETER, "invalid libav_output");
@@ -107,12 +108,13 @@ static int __ffmpeg_get_image_from_frame(AVFrame *frame, heif_color_format_e col
 
        output = g_new0(heif_image_t, 1);
 
-       output->size = (size_t)av_image_get_buffer_size(pix_fmt, frame->width, frame->height, 1);
-       if (output->size <= 0) {
-               heif_error("av_image_get_buffer_size fail [%d x %d]", frame->width, frame->height);
+       buffer_size = av_image_get_buffer_size(pix_fmt, frame->width, frame->height, 1);
+       if (buffer_size <= 0) {
+               heif_error("av_image_get_buffer_size fail %d [%d x %d]", buffer_size, frame->width, frame->height);
                goto FAIL;
        }
 
+       output->size = (size_t)buffer_size;
        output->width = (unsigned int)frame->width;
        output->height = (unsigned int)frame->height;
        output->format = colr_fmt;