[FFmpeg-cvslog] r25802 - trunk/libavfilter/vf_aspect.c

stefano subversion
Mon Nov 22 23:03:30 CET 2010


Author: stefano
Date: Mon Nov 22 23:03:30 2010
New Revision: 25802

Log:
Implement robust parsing in aspect filters.

Modified:
   trunk/libavfilter/vf_aspect.c

Modified: trunk/libavfilter/vf_aspect.c
==============================================================================
--- trunk/libavfilter/vf_aspect.c	Mon Nov 22 23:03:27 2010	(r25801)
+++ trunk/libavfilter/vf_aspect.c	Mon Nov 22 23:03:30 2010	(r25802)
@@ -34,22 +34,24 @@ static av_cold int init(AVFilterContext 
     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)



More information about the ffmpeg-cvslog mailing list