Implement robust parsing in aspect filters.
Originally committed as revision 25802 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
eee0ef5e4f
commit
7de19a3264
@ -34,22 +34,24 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
|
|||||||
AspectContext *aspect = ctx->priv;
|
AspectContext *aspect = ctx->priv;
|
||||||
double ratio;
|
double ratio;
|
||||||
int64_t gcd;
|
int64_t gcd;
|
||||||
|
char c = 0;
|
||||||
|
|
||||||
if (args) {
|
if (args) {
|
||||||
if (sscanf(args, "%d:%d", &aspect->aspect.num, &aspect->aspect.den) < 2) {
|
if (sscanf(args, "%d:%d%c", &aspect->aspect.num, &aspect->aspect.den, &c) != 2)
|
||||||
if (sscanf(args, "%lf", &ratio) < 1) {
|
if (sscanf(args, "%lf%c", &ratio, &c) == 1)
|
||||||
av_log(ctx, AV_LOG_ERROR,
|
aspect->aspect = av_d2q(ratio, 100);
|
||||||
"Invalid string '%s' for aspect ratio.\n", args);
|
|
||||||
return AVERROR(EINVAL);
|
if (c || aspect->aspect.num <= 0 || aspect->aspect.den <= 0) {
|
||||||
}
|
av_log(ctx, AV_LOG_ERROR,
|
||||||
aspect->aspect = av_d2q(ratio, 100);
|
"Invalid string '%s' for aspect ratio.\n", args);
|
||||||
} else {
|
return AVERROR(EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
gcd = av_gcd(FFABS(aspect->aspect.num), FFABS(aspect->aspect.den));
|
gcd = av_gcd(FFABS(aspect->aspect.num), FFABS(aspect->aspect.den));
|
||||||
if (gcd) {
|
if (gcd) {
|
||||||
aspect->aspect.num /= gcd;
|
aspect->aspect.num /= gcd;
|
||||||
aspect->aspect.den /= gcd;
|
aspect->aspect.den /= gcd;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aspect->aspect.den == 0)
|
if (aspect->aspect.den == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user