Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMark Harris <mark.hsj@gmail.com>2018-05-28 03:47:28 +0300
committerMark Harris <mark.hsj@gmail.com>2018-05-28 10:37:54 +0300
commit697beca22dcdf04ee7720218741f34a7ec0bb86d (patch)
tree03719e79d91088cae878a375cc313fb15e89fb33 /src
parent287cb030ab8a59dcecbb7ab8ea689f6dd5eb38b8 (diff)
Only call isqrt32() with a positive argument
Fixes test_opus_projection failure under ubsan, due to clz(0).
Diffstat (limited to 'src')
-rw-r--r--src/opus_multistream_encoder.c6
-rw-r--r--src/opus_projection_encoder.c10
2 files changed, 10 insertions, 6 deletions
diff --git a/src/opus_multistream_encoder.c b/src/opus_multistream_encoder.c
index 1df9e7db..aa48a61b 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 1c403c31..1fbcf471 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;
}