shithub: opus

Download patch

ref: d8302fc093430a342297caae7ee1906bfa6202b0
parent: 733b47f31cfa72eb31323dc8b3dd1ba16074a106
author: Gregory Maxwell <[email protected]>
date: Tue Nov 19 03:29:06 EST 2013

Validate channel count in opus_demo.

--- a/src/opus_demo.c
+++ b/src/opus_demo.c
@@ -308,13 +308,6 @@
     }
     sampling_rate = (opus_int32)atol(argv[args]);
     args++;
-    channels = atoi(argv[args]);
-    args++;
-    if (!decode_only)
-    {
-       bitrate_bps = (opus_int32)atol(argv[args]);
-       args++;
-    }
 
     if (sampling_rate != 8000 && sampling_rate != 12000
      && sampling_rate != 16000 && sampling_rate != 24000
@@ -325,6 +318,21 @@
         return EXIT_FAILURE;
     }
     frame_size = sampling_rate/50;
+
+    channels = atoi(argv[args]);
+    args++;
+
+    if (channels < 1 || channels > 2)
+    {
+        fprintf(stderr, "Opus_demo supports only 1 or 2 channels.\n");
+        return EXIT_FAILURE;
+    }
+
+    if (!decode_only)
+    {
+       bitrate_bps = (opus_int32)atol(argv[args]);
+       args++;
+    }
 
     /* defaults: */
     use_vbr = 1;