diff --git a/celt/mathops.c b/celt/mathops.c
index 78b52cc84a7d439efdf14ab1c3e6e675b34170ee..6ee9b9e101618724170e38452185638ad7dc8ed4 100644
--- a/celt/mathops.c
+++ b/celt/mathops.c
@@ -38,7 +38,8 @@
 #include "mathops.h"
 
 /*Compute floor(sqrt(_val)) with exact arithmetic.
-  This has been tested on all possible 32-bit inputs.*/
+  _val must be greater than 0.
+  This has been tested on all possible 32-bit inputs greater than 0.*/
 unsigned isqrt32(opus_uint32 _val){
   unsigned b;
   unsigned g;
diff --git a/src/opus_multistream_encoder.c b/src/opus_multistream_encoder.c
index 1df9e7db84bab676c782caa5f62fcd600eccb3de..aa48a61b08deaf63e03b5b18424eb97bee6c8f47 100644
--- a/src/opus_multistream_encoder.c
+++ b/src/opus_multistream_encoder.c
@@ -108,12 +108,14 @@ static int validate_ambisonics(int nb_channels, int *nb_streams, int *nb_coupled
    int acn_channels;
    int nondiegetic_channels;
 
+   if (nb_channels < 1 || nb_channels > 227)
+      return 0;
+
    order_plus_one = isqrt32(nb_channels);
    acn_channels = order_plus_one * order_plus_one;
    nondiegetic_channels = nb_channels - acn_channels;
 
-   if (order_plus_one < 1 || order_plus_one > 15 ||
-       (nondiegetic_channels != 0 && nondiegetic_channels != 2))
+   if (nondiegetic_channels != 0 && nondiegetic_channels != 2)
       return 0;
 
    if (nb_streams)
diff --git a/src/opus_projection_encoder.c b/src/opus_projection_encoder.c
index 1c403c3168e05ff7dd353605896d53af0e46936e..1fbcf471f74ae0ab4af5cd7702b4972e492b43e2 100644
--- a/src/opus_projection_encoder.c
+++ b/src/opus_projection_encoder.c
@@ -86,15 +86,17 @@ static int get_order_plus_one_from_channels(int channels, int *order_plus_one)
   /* Allowed numbers of channels:
    * (1 + n)^2 + 2j, for n = 0...14 and j = 0 or 1.
    */
+  if (channels < 1 || channels > 227)
+    return OPUS_BAD_ARG;
+
   order_plus_one_ = isqrt32(channels);
   acn_channels = order_plus_one_ * order_plus_one_;
   nondiegetic_channels = channels - acn_channels;
+  if (nondiegetic_channels != 0 && nondiegetic_channels != 2)
+    return OPUS_BAD_ARG;
+
   if (order_plus_one)
     *order_plus_one = order_plus_one_;
-
-  if (order_plus_one_ < 1 || order_plus_one_ > 15 ||
-      (nondiegetic_channels != 0 && nondiegetic_channels != 2))
-    return OPUS_BAD_ARG;
   return OPUS_OK;
 }