From d8302fc093430a342297caae7ee1906bfa6202b0 Mon Sep 17 00:00:00 2001
From: Gregory Maxwell <greg@xiph.org>
Date: Tue, 19 Nov 2013 08:29:06 -0800
Subject: [PATCH] Validate channel count in opus_demo.

---
 src/opus_demo.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/opus_demo.c b/src/opus_demo.c
index f2349b230..f8cdf0310 100644
--- a/src/opus_demo.c
+++ b/src/opus_demo.c
@@ -308,13 +308,6 @@ int main(int argc, char *argv[])
     }
     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
@@ -326,6 +319,21 @@ int main(int argc, char *argv[])
     }
     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;
     bandwidth = OPUS_AUTO;
-- 
GitLab