History

lavfi/unsharp: clarify invalid filter param constraints

Clarify failure in case of x/y building a too big matrix. Example: $ ffmpeg -hide_banner -f lavfi -i color=c=white:size=640x360,unsharp=lx=5:ly=23 -f null -t 1 - [Parsed_unsharp_1 @ 0x5650e1c30240] luma matrix size (lx/2+ly/2)*2=26 greater than maximum value 25 color=c=white:size=640x360,unsharp=lx=5:ly=23: Invalid argument Fix trac issue: http://trac.ffmpeg.org/ticket/6033

Stefano Sabatini committed 3 years ago

Commit 9d140ec1 parent 774d3581 file · +22 −8Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_unsharp.c+22−8
@@ -171,7 +171,10 @@ static int apply_unsharp_c(AVFilterContext *ctx, AVFrame *in, AVFrame *out) · 170 unmodified lines
171171 return 0;
172172 }
173173
174−static void set_filter_param(UnsharpFilterParam *fp, int msize_x, int msize_y, float amount)
174+#define MAX_SCALEBITS 25
175+
176+static int set_filter_param(AVFilterContext *ctx, const char *name, const char *short_name,
177+ UnsharpFilterParam *fp, int msize_x, int msize_y, float amount)
175178 {
176179 fp->msize_x = msize_x;
177180 fp->msize_y = msize_y;
@@ -181,20 +184,31 @@ static void set_filter_param(UnsharpFilterParam *fp, int msize_x, int msize_y, f · 3 unmodified lines
181184 fp->steps_y = msize_y / 2;
182185 fp->scalebits = (fp->steps_x + fp->steps_y) * 2;
183186 fp->halfscale = 1 << (fp->scalebits - 1);
187+
188+ if (fp->scalebits > MAX_SCALEBITS) {
189+ av_log(ctx, AV_LOG_ERROR, "%s matrix size (%sx/2+%sy/2)*2=%d greater than maximum value %d\n",
190+ name, short_name, short_name, fp->scalebits, MAX_SCALEBITS);
191+ return AVERROR(EINVAL);
192+ }
193+
194+ return 0;
184195 }
185196
186197 static av_cold int init(AVFilterContext *ctx)
187198 {
188199 UnsharpContext *s = ctx->priv;
200+ int ret;
189201
190− set_filter_param(&s->luma, s->lmsize_x, s->lmsize_y, s->lamount);
191− set_filter_param(&s->chroma, s->cmsize_x, s->cmsize_y, s->camount);
192− set_filter_param(&s->alpha, s->amsize_x, s->amsize_y, s->aamount);
202+#define SET_FILTER_PARAM(name_, short_) \
203+ ret = set_filter_param(ctx, #name_, #short_, &s->name_, \
204+ s->short_##msize_x, s->short_##msize_y, s->short_##amount); \
205+ if (ret < 0) \
206+ return ret; \
207+
208+ SET_FILTER_PARAM(luma, l);
209+ SET_FILTER_PARAM(chroma, c);
210+ SET_FILTER_PARAM(alpha, a);
193211
194− if (s->luma.scalebits >= 26 || s->chroma.scalebits >= 26 || s->alpha.scalebits >= 26) {
195− av_log(ctx, AV_LOG_ERROR, "luma or chroma or alpha matrix size too big\n");
196− return AVERROR(EINVAL);
197− }
198212 s->apply_unsharp = apply_unsharp_c;
199213 return 0;
200214 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t