diff options
author | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2010-11-22 22:03:30 +0000 |
---|---|---|
committer | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2010-11-22 22:03:30 +0000 |
commit | 7de19a3264f530d14b509eff0c4a8d6e62c0f984 (patch) | |
tree | eac6c908af1397f8dff96d6dd6b563b4099ffd08 | |
parent | eee0ef5e4f6cce70043f8f2d81f66dbbacb292cc (diff) | |
download | ffmpeg-7de19a3264f530d14b509eff0c4a8d6e62c0f984.tar.gz |
Implement robust parsing in aspect filters.
Originally committed as revision 25802 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavfilter/vf_aspect.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/libavfilter/vf_aspect.c b/libavfilter/vf_aspect.c index bb7690b7d2..97740f103d 100644 --- a/libavfilter/vf_aspect.c +++ b/libavfilter/vf_aspect.c @@ -34,22 +34,24 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) AspectContext *aspect = ctx->priv; double ratio; int64_t gcd; + char c = 0; if (args) { - if (sscanf(args, "%d:%d", &aspect->aspect.num, &aspect->aspect.den) < 2) { - if (sscanf(args, "%lf", &ratio) < 1) { - av_log(ctx, AV_LOG_ERROR, - "Invalid string '%s' for aspect ratio.\n", args); - return AVERROR(EINVAL); - } - aspect->aspect = av_d2q(ratio, 100); - } else { + if (sscanf(args, "%d:%d%c", &aspect->aspect.num, &aspect->aspect.den, &c) != 2) + if (sscanf(args, "%lf%c", &ratio, &c) == 1) + aspect->aspect = av_d2q(ratio, 100); + + if (c || aspect->aspect.num <= 0 || aspect->aspect.den <= 0) { + av_log(ctx, AV_LOG_ERROR, + "Invalid string '%s' for aspect ratio.\n", args); + return AVERROR(EINVAL); + } + gcd = av_gcd(FFABS(aspect->aspect.num), FFABS(aspect->aspect.den)); if (gcd) { aspect->aspect.num /= gcd; aspect->aspect.den /= gcd; } - } } if (aspect->aspect.den == 0) |