From: "Kacper Michajłow" <kasper93@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: "Kacper Michajłow" <kasper93@gmail.com> Subject: [FFmpeg-devel] [PATCH] avfilter/vf_scale: validate values before converting to integer Date: Wed, 10 Jul 2024 17:24:01 +0200 Message-ID: <20240710152401.1192-1-kasper93@gmail.com> (raw) Fixes the conversion of double values to integer, which may be out of the representable range. Also, bail out on overflow check instead of printing an error only. Found by OSS-Fuzz. Signed-off-by: Kacper Michajłow <kasper93@gmail.com> --- libavfilter/vf_scale.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index ae7356fd7b..66bb81dd1f 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -537,7 +537,6 @@ static int scale_eval_dimensions(AVFilterContext *ctx) const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format); char *expr; - int eval_w, eval_h; int ret; double res; const AVPixFmtDescriptor *main_desc; @@ -588,26 +587,20 @@ static int scale_eval_dimensions(AVFilterContext *ctx) } res = av_expr_eval(scale->w_pexpr, scale->var_values, NULL); - eval_w = scale->var_values[VAR_OUT_W] = scale->var_values[VAR_OW] = (int) res == 0 ? inlink->w : (int) res; - - res = av_expr_eval(scale->h_pexpr, scale->var_values, NULL); - if (isnan(res)) { - expr = scale->h_expr; + if (isnan(res) || res < INT_MIN || res > INT_MAX) { + expr = scale->w_expr; ret = AVERROR(EINVAL); goto fail; } - eval_h = scale->var_values[VAR_OUT_H] = scale->var_values[VAR_OH] = (int) res == 0 ? inlink->h : (int) res; + scale->w = scale->var_values[VAR_OUT_W] = scale->var_values[VAR_OW] = res == 0 ? inlink->w : res; - res = av_expr_eval(scale->w_pexpr, scale->var_values, NULL); - if (isnan(res)) { - expr = scale->w_expr; + res = av_expr_eval(scale->h_pexpr, scale->var_values, NULL); + if (isnan(res) || res < INT_MIN || res > INT_MAX) { + expr = scale->h_expr; ret = AVERROR(EINVAL); goto fail; } - eval_w = scale->var_values[VAR_OUT_W] = scale->var_values[VAR_OW] = (int) res == 0 ? inlink->w : (int) res; - - scale->w = eval_w; - scale->h = eval_h; + scale->h = scale->var_values[VAR_OUT_H] = scale->var_values[VAR_OH] = res == 0 ? inlink->h : res; return 0; @@ -642,11 +635,15 @@ static int config_props(AVFilterLink *outlink) scale->force_original_aspect_ratio, scale->force_divisible_by); - if (outlink->w > INT_MAX || - outlink->h > INT_MAX || - (outlink->h * inlink->w) > INT_MAX || - (outlink->w * inlink->h) > INT_MAX) + if (outlink->w <= 0 || + outlink->h <= 0 || + outlink->h > INT_MAX / inlink->w || + outlink->w > INT_MAX / inlink->h) + { av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n"); + ret = AVERROR(EINVAL); + goto fail; + } /* TODO: make algorithm configurable */ -- 2.43.0 _______________________________________________ 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".
reply other threads:[~2024-07-10 15:25 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240710152401.1192-1-kasper93@gmail.com \ --to=kasper93@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
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