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] lavfi/unsharp: clarify invalid filter param constraints
@ 2023-03-25 16:20 Stefano Sabatini
  2023-03-28 22:00 ` Stefano Sabatini
  0 siblings, 1 reply; 3+ messages in thread
From: Stefano Sabatini @ 2023-03-25 16:20 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Stefano Sabatini

Clarify failure in case of x/y building a too big matrix size.

Example:
$ ffmpeg -hide_banner -f lavfi -i color=c=white:size=640x360,unsharp=lx=4:ly=21:la=-1:cx=5:cy=23:ca=0 -f null -
[Parsed_unsharp_1 @ 0x55b100e7d740] chroma matrix size (cx/2+cy/2)*2=26 greater than maximum value 25
color=c=white:size=640x360,unsharp=lx=4:ly=21:la=-1:cx=5:cy=23:ca=0: Invalid argument

Fix trac issue:
http://trac.ffmpeg.org/ticket/6033
---
 libavfilter/vf_unsharp.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c
index e88e732c9e..5e17ebce1e 100644
--- a/libavfilter/vf_unsharp.c
+++ b/libavfilter/vf_unsharp.c
@@ -171,7 +171,10 @@ static int apply_unsharp_c(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
     return 0;
 }
 
-static void set_filter_param(UnsharpFilterParam *fp, int msize_x, int msize_y, float amount)
+#define MAX_SCALEBITS 25
+
+static int set_filter_param(AVFilterContext *ctx, const char *name, const char *short_name,
+                            UnsharpFilterParam *fp, int msize_x, int msize_y, float amount)
 {
     fp->msize_x = msize_x;
     fp->msize_y = msize_y;
@@ -181,20 +184,31 @@ static void set_filter_param(UnsharpFilterParam *fp, int msize_x, int msize_y, f
     fp->steps_y = msize_y / 2;
     fp->scalebits = (fp->steps_x + fp->steps_y) * 2;
     fp->halfscale = 1 << (fp->scalebits - 1);
+
+    if (fp->scalebits > MAX_SCALEBITS) {
+        av_log(ctx, AV_LOG_ERROR, "%s matrix size (%sx/2+%sy/2)*2=%d greater than maximum value %d\n",
+               name, short_name, short_name, fp->scalebits, MAX_SCALEBITS);
+        return AVERROR(EINVAL);
+    }
+
+    return 0;
 }
 
 static av_cold int init(AVFilterContext *ctx)
 {
     UnsharpContext *s = ctx->priv;
+    int ret;
 
-    set_filter_param(&s->luma,   s->lmsize_x, s->lmsize_y, s->lamount);
-    set_filter_param(&s->chroma, s->cmsize_x, s->cmsize_y, s->camount);
-    set_filter_param(&s->alpha,  s->amsize_x, s->amsize_y, s->aamount);
+#define SET_FILTER_PARAM(name_, short_)                                 \
+    ret = set_filter_param(ctx, #name_, #short_, &s->name_,             \
+                           s->short_##msize_x, s->short_##msize_y, s->short_##amount); \
+    if (ret < 0)                                                        \
+        return ret;                                                     \
+
+    SET_FILTER_PARAM(luma, l);
+    SET_FILTER_PARAM(chroma, c);
+    SET_FILTER_PARAM(alpha, a);
 
-    if (s->luma.scalebits >= 26 || s->chroma.scalebits >= 26 || s->alpha.scalebits >= 26) {
-        av_log(ctx, AV_LOG_ERROR, "luma or chroma or alpha matrix size too big\n");
-        return AVERROR(EINVAL);
-    }
     s->apply_unsharp = apply_unsharp_c;
     return 0;
 }
-- 
2.25.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] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavfi/unsharp: clarify invalid filter param constraints
  2023-03-25 16:20 [FFmpeg-devel] [PATCH] lavfi/unsharp: clarify invalid filter param constraints Stefano Sabatini
@ 2023-03-28 22:00 ` Stefano Sabatini
  2023-04-02 15:09   ` Stefano Sabatini
  0 siblings, 1 reply; 3+ messages in thread
From: Stefano Sabatini @ 2023-03-28 22:00 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On date Saturday 2023-03-25 17:20:44 +0100, Stefano Sabatini wrote:
> Clarify failure in case of x/y building a too big matrix size.
> 
> Example:
> $ ffmpeg -hide_banner -f lavfi -i color=c=white:size=640x360,unsharp=lx=4:ly=21:la=-1:cx=5:cy=23:ca=0 -f null -
> [Parsed_unsharp_1 @ 0x55b100e7d740] chroma matrix size (cx/2+cy/2)*2=26 greater than maximum value 25
> color=c=white:size=640x360,unsharp=lx=4:ly=21:la=-1:cx=5:cy=23:ca=0: Invalid argument
> 
> Fix trac issue:
> http://trac.ffmpeg.org/ticket/6033
> ---
>  libavfilter/vf_unsharp.c | 30 ++++++++++++++++++++++--------
>  1 file changed, 22 insertions(+), 8 deletions(-)

Will apply in a few days if I see no comments.
_______________________________________________
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] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavfi/unsharp: clarify invalid filter param constraints
  2023-03-28 22:00 ` Stefano Sabatini
@ 2023-04-02 15:09   ` Stefano Sabatini
  0 siblings, 0 replies; 3+ messages in thread
From: Stefano Sabatini @ 2023-04-02 15:09 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On date Wednesday 2023-03-29 00:00:22 +0200, Stefano Sabatini wrote:
> On date Saturday 2023-03-25 17:20:44 +0100, Stefano Sabatini wrote:
> > Clarify failure in case of x/y building a too big matrix size.
> > 
> > Example:
> > $ ffmpeg -hide_banner -f lavfi -i color=c=white:size=640x360,unsharp=lx=4:ly=21:la=-1:cx=5:cy=23:ca=0 -f null -
> > [Parsed_unsharp_1 @ 0x55b100e7d740] chroma matrix size (cx/2+cy/2)*2=26 greater than maximum value 25
> > color=c=white:size=640x360,unsharp=lx=4:ly=21:la=-1:cx=5:cy=23:ca=0: Invalid argument
> > 
> > Fix trac issue:
> > http://trac.ffmpeg.org/ticket/6033
> > ---
> >  libavfilter/vf_unsharp.c | 30 ++++++++++++++++++++++--------
> >  1 file changed, 22 insertions(+), 8 deletions(-)
> 
> Will apply in a few days if I see no comments.

Applied.
_______________________________________________
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] 3+ messages in thread

end of thread, other threads:[~2023-04-02 15:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-25 16:20 [FFmpeg-devel] [PATCH] lavfi/unsharp: clarify invalid filter param constraints Stefano Sabatini
2023-03-28 22:00 ` Stefano Sabatini
2023-04-02 15:09   ` Stefano Sabatini

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