shithub: libvpx

Download patch

ref: 1b27e93cd13ff60798e31634ddb362fa7aa9749d
parent: dba053898a662923e8750021314e1e90d0b92f80
author: John Koleszar <jkoleszar@google.com>
date: Wed Apr 25 13:08:56 EDT 2012

vpxenc: validate rational arguments

Trap negative values and zero denominators at the point where they're
parsed.

Change-Id: I1ec9da5d4e95d3ef539860883041330ecec2f345

--- a/vpxenc.c
+++ b/vpxenc.c
@@ -1542,6 +1542,23 @@
 };
 
 
+void validate_positive_rational(const char          *msg,
+                                struct vpx_rational *rat)
+{
+    if (rat->den < 0)
+    {
+        rat->num *= -1;
+        rat->den *= -1;
+    }
+
+    if (rat->num < 0)
+        die("Error: %s must be positive\n", msg);
+
+    if (!rat->den)
+        die("Error: %s has zero denominator\n", msg);
+}
+
+
 static void parse_global_config(struct global_config *global, char **argv)
 {
     char       **argi, **argj;
@@ -1610,6 +1627,7 @@
         else if (arg_match(&arg, &framerate, argi))
         {
             global->framerate = arg_parse_rational(&arg);
+            validate_positive_rational(arg.name, &global->framerate);
             global->have_framerate = 1;
         }
         else if (arg_match(&arg,&out_part, argi))
@@ -1807,7 +1825,10 @@
         else if (arg_match(&arg, &stereo_mode, argi))
             config->stereo_fmt = arg_parse_enum_or_int(&arg);
         else if (arg_match(&arg, &timebase, argi))
+        {
             config->cfg.g_timebase = arg_parse_rational(&arg);
+            validate_positive_rational(arg.name, &config->cfg.g_timebase);
+        }
         else if (arg_match(&arg, &error_resilient, argi))
             config->cfg.g_error_resilient = arg_parse_uint(&arg);
         else if (arg_match(&arg, &lag_in_frames, argi))