changeset 28702:c4cf47906bd2 stable

Fix input validation for audioplayer (bug #57939). * audiodevinfo.cc (F__player_audioplayer__): Replace '||' with '&&' in if conditional checking for correct NBITS input. * audioplayer.m: Add BIST tests for checking NBITS input.
author Rik <rik@octave.org>
date Sun, 31 May 2020 09:56:56 -0700
parents 7d63f42e94be
children f6743b1200ff c435048c2796
files libinterp/dldfcn/audiodevinfo.cc scripts/audio/@audioplayer/audioplayer.m
diffstat 2 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/audiodevinfo.cc	Wed Sep 09 15:15:47 2020 -0400
+++ b/libinterp/dldfcn/audiodevinfo.cc	Sun May 31 09:56:56 2020 -0700
@@ -2383,7 +2383,7 @@
     {
       // FIXME: Should be able to support 32-bit streams (bug #57939)
       int nbits = args(2).int_value ();
-      if (nbits != 8 || nbits != 16 || nbits != 24)
+      if (nbits != 8 && nbits != 16 && nbits != 24)
         error ("audioplayer: NBITS must be 8, 16, or 24");
 
       switch (args.length ())
--- a/scripts/audio/@audioplayer/audioplayer.m	Wed Sep 09 15:15:47 2020 -0400
+++ b/scripts/audio/@audioplayer/audioplayer.m	Sun May 31 09:56:56 2020 -0700
@@ -175,6 +175,15 @@
 %! properties = get (player, {"SampleRate", "Tag", "UserData"});
 %! assert (properties, {8000, "tag", [1, 2; 3, 4]});
 
+%!testif HAVE_PORTAUDIO; audiodevinfo (0) > 0
+%! ## Verify nbits option only accepts 8, 16, 24
+%! fail ("audioplayer (1, 8e3, 9)", "NBITS must be 8, 16, or 24");
+%! fail ("audioplayer (1, 8e3, 32)", "NBITS must be 8, 16, or 24");
+%! player = audioplayer (1, 8e3, 8);
+%! player = audioplayer (1, 8e3, 16);
+%! player = audioplayer (1, 8e3, 24);
+
+## FIXME: Callbacks do not work currently (5/31/2020) so BIST tests commented.
 #%!function [sound, status] = callback (samples)
 #%!  sound = rand (samples, 2) - 0.5;
 #%!  status = 0;