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

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
171 return 0;171 return 0;
172}172}
173 173
174static void set_filter_param(UnsharpFilterParam *fp, int msize_x, int msize_y, float amount)174#define MAX_SCALEBITS 25
175
176static int set_filter_param(AVFilterContext *ctx, const char *name, const char *short_name,
177 UnsharpFilterParam *fp, int msize_x, int msize_y, float amount)
175{178{
176 fp->msize_x = msize_x;179 fp->msize_x = msize_x;
177 fp->msize_y = msize_y;180 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
181 fp->steps_y = msize_y / 2;184 fp->steps_y = msize_y / 2;
182 fp->scalebits = (fp->steps_x + fp->steps_y) * 2;185 fp->scalebits = (fp->steps_x + fp->steps_y) * 2;
183 fp->halfscale = 1 << (fp->scalebits - 1);186 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;
184}195}
185 196
186static av_cold int init(AVFilterContext *ctx)197static av_cold int init(AVFilterContext *ctx)
187{198{
188 UnsharpContext *s = ctx->priv;199 UnsharpContext *s = ctx->priv;
200 int ret;
189 201
190 set_filter_param(&s->luma, s->lmsize_x, s->lmsize_y, s->lamount);202#define SET_FILTER_PARAM(name_, short_) \
191 set_filter_param(&s->chroma, s->cmsize_x, s->cmsize_y, s->camount);203 ret = set_filter_param(ctx, #name_, #short_, &s->name_, \
192 set_filter_param(&s->alpha, s->amsize_x, s->amsize_y, s->aamount);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);
193 211
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 }
198 s->apply_unsharp = apply_unsharp_c;212 s->apply_unsharp = apply_unsharp_c;
199 return 0;213 return 0;
200}214}

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