changeset 28162:41750ce4752c stable

Better input validation for audioplayer (bug #57939). * audiodevinfo.cc (__player_audioplayer__): Validate that NBITS input is one of 8, 16, or 24.
author Rik <rik@octave.org>
date Sun, 15 Mar 2020 14:53:33 -0700
parents 54d6f1b5fab2
children b98b6e2490b2 a0492ac068f2
files libinterp/dldfcn/audiodevinfo.cc
diffstat 1 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/audiodevinfo.cc	Fri Mar 13 15:14:49 2020 -0700
+++ b/libinterp/dldfcn/audiodevinfo.cc	Sun Mar 15 14:53:33 2020 -0700
@@ -2378,16 +2378,24 @@
   recorder->set_y (args(0));
   recorder->set_fs (args(1).int_value ());
 
-  switch (args.length ())
+  if (args.length () > 2)
     {
-    case 3:
-      recorder->set_nbits (args(2).int_value ());
-      break;
-
-    case 4:
-      recorder->set_nbits (args(2).int_value ());
-      recorder->set_id (args(3).int_value ());
-      break;
+      // FIXME: Should be able to support 32-bit streams (bug #57939)
+      int nbits = args(2).int_value ();
+      if (nbits != 8 || nbits != 16 || nbits != 24)
+        error ("audioplayer: NBITS must be 8, 16, or 24");
+
+      switch (args.length ())
+        {
+        case 3:
+          recorder->set_nbits (nbits);
+          break;
+
+        case 4:
+          recorder->set_nbits (nbits);
+          recorder->set_id (args(3).int_value ());
+          break;
+        }
     }
 
   if (is_function)