Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/3] avfilter/vf_ssim360: Use correct type in sizeof
@ 2023-03-12 21:52 Andreas Rheinhardt
  2023-03-12 21:53 ` [FFmpeg-devel] [PATCH 2/3] avfilter/vf_ssim360: Remove dead code Andreas Rheinhardt
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2023-03-12 21:52 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

SSIM360Context.ssim360_hist is an array of four pointers to double;
so sizeof(*ssim360_hist[0]) (=sizeof(double)) is the correct size
to use to calculate the amount of memory to allocate, not
sizeof(*ssim360_hist) (which is sizeof(double*)).

Use FF_ALLOCZ_TYPED_ARRAY to avoid this issue altogether.

Fixes Coverity issue #1520671.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/vf_ssim360.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_ssim360.c b/libavfilter/vf_ssim360.c
index 3eb8e43bbc..f8ce0744f2 100644
--- a/libavfilter/vf_ssim360.c
+++ b/libavfilter/vf_ssim360.c
@@ -1624,7 +1624,7 @@ static int config_output(AVFilterLink *outlink)
         memset(s->ssim360_percentile_sum, 0, sizeof(s->ssim360_percentile_sum));
 
         for (int i = 0; i < s->nb_components; i++) {
-            s->ssim360_hist[i] = av_calloc(SSIM360_HIST_SIZE, sizeof(*s->ssim360_hist));
+            FF_ALLOCZ_TYPED_ARRAY(s->ssim360_hist[i], SSIM360_HIST_SIZE);
             if (!s->ssim360_hist[i])
                 return AVERROR(ENOMEM);
         }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH 2/3] avfilter/vf_ssim360: Remove dead code
  2023-03-12 21:52 [FFmpeg-devel] [PATCH 1/3] avfilter/vf_ssim360: Use correct type in sizeof Andreas Rheinhardt
@ 2023-03-12 21:53 ` Andreas Rheinhardt
  2023-03-12 21:53 ` [FFmpeg-devel] [PATCH 3/3] avcodec/libx264: Fix leak in case of allocation failure Andreas Rheinhardt
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2023-03-12 21:53 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Fixes Coverity issue #1520669.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/vf_ssim360.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/libavfilter/vf_ssim360.c b/libavfilter/vf_ssim360.c
index f8ce0744f2..5794275c2c 100644
--- a/libavfilter/vf_ssim360.c
+++ b/libavfilter/vf_ssim360.c
@@ -1274,10 +1274,6 @@ static int parse_heatmaps(void *logctx, HeatmapList **proot,
             ret = AVERROR(ENOMEM);
             goto fail;
         }
-        if (!line) {
-            av_freep(&line);
-            break;
-        }
 
         // first value is frame id
         av_strtok(line, ",", &saveptr);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH 3/3] avcodec/libx264: Fix leak in case of allocation failure
  2023-03-12 21:52 [FFmpeg-devel] [PATCH 1/3] avfilter/vf_ssim360: Use correct type in sizeof Andreas Rheinhardt
  2023-03-12 21:53 ` [FFmpeg-devel] [PATCH 2/3] avfilter/vf_ssim360: Remove dead code Andreas Rheinhardt
@ 2023-03-12 21:53 ` Andreas Rheinhardt
  2023-03-13 13:22 ` [FFmpeg-devel] [PATCH 4/6] avcodec/libx264: Pass x264_picture_t* directly Andreas Rheinhardt
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2023-03-12 21:53 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Fixes Coverity issue #1518906.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/libx264.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index f65ac5dacc..e59939a8a7 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -503,6 +503,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         if (sei_data) {
             pic->extra_sei.payloads = av_mallocz(sizeof(pic->extra_sei.payloads[0]));
             if (pic->extra_sei.payloads == NULL) {
+                av_free(sei_data);
                 ret = AVERROR(ENOMEM);
                 goto fail;
             }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH 4/6] avcodec/libx264: Pass x264_picture_t* directly
  2023-03-12 21:52 [FFmpeg-devel] [PATCH 1/3] avfilter/vf_ssim360: Use correct type in sizeof Andreas Rheinhardt
  2023-03-12 21:53 ` [FFmpeg-devel] [PATCH 2/3] avfilter/vf_ssim360: Remove dead code Andreas Rheinhardt
  2023-03-12 21:53 ` [FFmpeg-devel] [PATCH 3/3] avcodec/libx264: Fix leak in case of allocation failure Andreas Rheinhardt
@ 2023-03-13 13:22 ` Andreas Rheinhardt
  2023-03-13 13:22 ` [FFmpeg-devel] [PATCH 5/6] avcodec/libx264: Use dedicated pointer for accesses Andreas Rheinhardt
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2023-03-13 13:22 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/libx264.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index e59939a8a7..df70e9df9b 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -311,11 +311,8 @@ static void reconfig_encoder(AVCodecContext *ctx, const AVFrame *frame)
     }
 }
 
-static void free_picture(AVCodecContext *ctx)
+static void free_picture(x264_picture_t *pic)
 {
-    X264Context *x4 = ctx->priv_data;
-    x264_picture_t *pic = &x4->pic;
-
     for (int i = 0; i < pic->extra_sei.num_payloads; i++)
         av_free(pic->extra_sei.payloads[i].payload);
     av_freep(&pic->extra_sei.payloads);
@@ -554,7 +551,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
     return 0;
 
 fail:
-    free_picture(ctx);
+    free_picture(pic);
     *ppic = NULL;
     return ret;
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH 5/6] avcodec/libx264: Use dedicated pointer for accesses
  2023-03-12 21:52 [FFmpeg-devel] [PATCH 1/3] avfilter/vf_ssim360: Use correct type in sizeof Andreas Rheinhardt
                   ` (2 preceding siblings ...)
  2023-03-13 13:22 ` [FFmpeg-devel] [PATCH 4/6] avcodec/libx264: Pass x264_picture_t* directly Andreas Rheinhardt
@ 2023-03-13 13:22 ` Andreas Rheinhardt
  2023-03-13 13:22 ` [FFmpeg-devel] [PATCH 6/6] avcodec/libx264: Use av_pix_fmt_count_planes() where appropriate Andreas Rheinhardt
  2023-03-13 22:53 ` [FFmpeg-devel] [PATCH 1/3] avfilter/vf_ssim360: Use correct type in sizeof Jan Ekström
  5 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2023-03-13 13:22 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/libx264.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index df70e9df9b..94006d2b20 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -498,19 +498,19 @@ FF_ENABLE_DEPRECATION_WARNINGS
             goto fail;
 
         if (sei_data) {
-            pic->extra_sei.payloads = av_mallocz(sizeof(pic->extra_sei.payloads[0]));
-            if (pic->extra_sei.payloads == NULL) {
+            sei->payloads = av_mallocz(sizeof(sei->payloads[0]));
+            if (!sei->payloads) {
                 av_free(sei_data);
                 ret = AVERROR(ENOMEM);
                 goto fail;
             }
 
-            pic->extra_sei.sei_free = av_free;
+            sei->sei_free = av_free;
 
-            pic->extra_sei.payloads[0].payload_size = sei_size;
-            pic->extra_sei.payloads[0].payload = sei_data;
-            pic->extra_sei.num_payloads = 1;
-            pic->extra_sei.payloads[0].payload_type = 4;
+            sei->payloads[0].payload_size = sei_size;
+            sei->payloads[0].payload      = sei_data;
+            sei->payloads[0].payload_type = 4;
+            sei->num_payloads = 1;
         }
     }
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH 6/6] avcodec/libx264: Use av_pix_fmt_count_planes() where appropriate
  2023-03-12 21:52 [FFmpeg-devel] [PATCH 1/3] avfilter/vf_ssim360: Use correct type in sizeof Andreas Rheinhardt
                   ` (3 preceding siblings ...)
  2023-03-13 13:22 ` [FFmpeg-devel] [PATCH 5/6] avcodec/libx264: Use dedicated pointer for accesses Andreas Rheinhardt
@ 2023-03-13 13:22 ` Andreas Rheinhardt
  2023-03-13 22:53 ` [FFmpeg-devel] [PATCH 1/3] avfilter/vf_ssim360: Use correct type in sizeof Jan Ekström
  5 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2023-03-13 13:22 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

This also fixes the number of planes for the NV formats
(this seems to not have caused any problems).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/libx264.c | 24 +-----------------------
 1 file changed, 1 insertion(+), 23 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 94006d2b20..92828fabc3 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -189,28 +189,6 @@ static int encode_nals(AVCodecContext *ctx, AVPacket *pkt,
     return 1;
 }
 
-static int avfmt2_num_planes(int avfmt)
-{
-    switch (avfmt) {
-    case AV_PIX_FMT_YUV420P:
-    case AV_PIX_FMT_YUVJ420P:
-    case AV_PIX_FMT_YUV420P9:
-    case AV_PIX_FMT_YUV420P10:
-    case AV_PIX_FMT_YUV444P:
-        return 3;
-
-    case AV_PIX_FMT_BGR0:
-    case AV_PIX_FMT_BGR24:
-    case AV_PIX_FMT_RGB24:
-    case AV_PIX_FMT_GRAY8:
-    case AV_PIX_FMT_GRAY10:
-        return 1;
-
-    default:
-        return 3;
-    }
-}
-
 static void reconfig_encoder(AVCodecContext *ctx, const AVFrame *frame)
 {
     X264Context *x4 = ctx->priv_data;
@@ -440,7 +418,7 @@ static int setup_frame(AVCodecContext *ctx, const AVFrame *frame,
 #endif
     if (bit_depth > 8)
         pic->img.i_csp |= X264_CSP_HIGH_DEPTH;
-    pic->img.i_plane = avfmt2_num_planes(ctx->pix_fmt);
+    pic->img.i_plane = av_pix_fmt_count_planes(ctx->pix_fmt);
 
     for (int i = 0; i < pic->img.i_plane; i++) {
         pic->img.plane[i]    = frame->data[i];
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/3] avfilter/vf_ssim360: Use correct type in sizeof
  2023-03-12 21:52 [FFmpeg-devel] [PATCH 1/3] avfilter/vf_ssim360: Use correct type in sizeof Andreas Rheinhardt
                   ` (4 preceding siblings ...)
  2023-03-13 13:22 ` [FFmpeg-devel] [PATCH 6/6] avcodec/libx264: Use av_pix_fmt_count_planes() where appropriate Andreas Rheinhardt
@ 2023-03-13 22:53 ` Jan Ekström
  5 siblings, 0 replies; 7+ messages in thread
From: Jan Ekström @ 2023-03-13 22:53 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Sun, Mar 12, 2023 at 11:52 PM Andreas Rheinhardt
<andreas.rheinhardt@outlook.com> wrote:
>
> SSIM360Context.ssim360_hist is an array of four pointers to double;
> so sizeof(*ssim360_hist[0]) (=sizeof(double)) is the correct size
> to use to calculate the amount of memory to allocate, not
> sizeof(*ssim360_hist) (which is sizeof(double*)).
>
> Use FF_ALLOCZ_TYPED_ARRAY to avoid this issue altogether.
>
> Fixes Coverity issue #1520671.
>

This set LGTM. Nice fixes and clean-ups in both vf_ssim360 and libx264.

Jan
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-13 22:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-12 21:52 [FFmpeg-devel] [PATCH 1/3] avfilter/vf_ssim360: Use correct type in sizeof Andreas Rheinhardt
2023-03-12 21:53 ` [FFmpeg-devel] [PATCH 2/3] avfilter/vf_ssim360: Remove dead code Andreas Rheinhardt
2023-03-12 21:53 ` [FFmpeg-devel] [PATCH 3/3] avcodec/libx264: Fix leak in case of allocation failure Andreas Rheinhardt
2023-03-13 13:22 ` [FFmpeg-devel] [PATCH 4/6] avcodec/libx264: Pass x264_picture_t* directly Andreas Rheinhardt
2023-03-13 13:22 ` [FFmpeg-devel] [PATCH 5/6] avcodec/libx264: Use dedicated pointer for accesses Andreas Rheinhardt
2023-03-13 13:22 ` [FFmpeg-devel] [PATCH 6/6] avcodec/libx264: Use av_pix_fmt_count_planes() where appropriate Andreas Rheinhardt
2023-03-13 22:53 ` [FFmpeg-devel] [PATCH 1/3] avfilter/vf_ssim360: Use correct type in sizeof Jan Ekström

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git