[FFmpeg-devel] [PATCH] Implement robust parsing in aspect filters.

Stefano Sabatini stefano.sabatini-lala
Thu Nov 18 22:33:23 CET 2010


---
 libavfilter/vf_aspect.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/libavfilter/vf_aspect.c b/libavfilter/vf_aspect.c
index 04c07e7..610dfee 100644
--- a/libavfilter/vf_aspect.c
+++ b/libavfilter/vf_aspect.c
@@ -32,24 +32,31 @@ typedef struct {
 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
 {
     AspectContext *aspect = ctx->priv;
-    double  ratio;
     int64_t gcd;
 
     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 {
+        const char *p;
+        char *tail;
+
+        p = strchr(args, ':');
+        if (p) {
+            aspect->aspect.num = strtol(args, &tail, 10);
+            if (tail == p)
+                aspect->aspect.den = strtol(tail+1, &tail, 10);
+        } else
+            aspect->aspect = av_d2q(strtod(args, &tail), 100);
+
+        if (*tail || 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)
-- 
1.7.1




More information about the ffmpeg-devel mailing list