aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Ragir <akshay.ragir@ittiam.com>2023-10-12 12:43:26 +0530
committerDivya B M <89966460+divya-bm@users.noreply.github.com>2023-10-12 19:24:54 +0530
commitfcf3e9af7de03133c4d1be76555638dacac85347 (patch)
treef07c073e27d13206e6c9561f8d8ccabb85aa9ced
parente8d026548e88221580cbaeb7a8906bced0295402 (diff)
downloadlibxaac-fcf3e9af7de03133c4d1be76555638dacac85347.tar.gz
Fix for the Divide-by-zero in iaace_adapt_thr_to_pe
These changes handle the divide-by-zero runtime error reported when the active lines become zero in quantization. The issue is reported with AAC and the same changes are extended to USAC. Bug: ossFuzz: 62977 Test: poc in bug
-rw-r--r--encoder/ixheaace_adjust_threshold.c22
-rw-r--r--encoder/ixheaace_fd_qc_adjthr.c20
2 files changed, 23 insertions, 19 deletions
diff --git a/encoder/ixheaace_adjust_threshold.c b/encoder/ixheaace_adjust_threshold.c
index 0bf1f38..9e4e91c 100644
--- a/encoder/ixheaace_adjust_threshold.c
+++ b/encoder/ixheaace_adjust_threshold.c
@@ -18,6 +18,7 @@
* Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/
+#include <float.h>
#include <math.h>
#include <stdlib.h>
@@ -857,7 +858,7 @@ static VOID iaace_adapt_thr_to_pe(
FLOAT32 const_part, const_part_no_ah;
FLOAT32 num_active_lines, num_active_lines_no_ah;
FLOAT32 desired_pe_no_ah;
- FLOAT32 avg_thr_exp, redval;
+ FLOAT32 redval = 0.0f;
WORD32 ah_flag[IXHEAACE_MAX_CH_IN_BS_ELE][MAXIMUM_GROUPED_SCALE_FACTOR_BAND];
FLOAT32 thr_exp[IXHEAACE_MAX_CH_IN_BS_ELE][MAXIMUM_GROUPED_SCALE_FACTOR_BAND];
WORD32 iteration;
@@ -869,13 +870,14 @@ static VOID iaace_adapt_thr_to_pe(
no_red_pe = pstr_qs_pe_data->pe;
const_part = pstr_qs_pe_data->const_part;
num_active_lines = pstr_qs_pe_data->num_active_lines;
- avg_thr_exp =
- (FLOAT32)pow(2.0f, (const_part - no_red_pe) / (INV_RED_EXP_VAL * num_active_lines));
- redval = (FLOAT32)pow(2.0f, (const_part - desired_pe) / (INV_RED_EXP_VAL * num_active_lines)) -
- avg_thr_exp;
- redval = MAX(0.0f, redval);
-
- iaace_reduce_thr(pstr_psy_out, ah_flag, thr_exp, redval, num_channels, chn);
+ if (num_active_lines > FLT_EPSILON) {
+ FLOAT32 avg_thr_exp =
+ (FLOAT32)pow(2.0f, (const_part - no_red_pe) / (INV_RED_EXP_VAL * num_active_lines));
+ redval = (FLOAT32)pow(2.0f, (const_part - desired_pe) / (INV_RED_EXP_VAL * num_active_lines))
+ - avg_thr_exp;
+ redval = MAX(0.0f, redval);
+ iaace_reduce_thr(pstr_psy_out, ah_flag, thr_exp, redval, num_channels, chn);
+ }
iaace_calc_sfb_pe_data(pstr_qs_pe_data, pstr_psy_out, num_channels, chn);
red_pe = pstr_qs_pe_data->pe;
@@ -887,8 +889,8 @@ static VOID iaace_adapt_thr_to_pe(
desired_pe_no_ah = MAX(desired_pe - (red_pe - red_pe_no_ah), 0);
- if (num_active_lines_no_ah > 0) {
- avg_thr_exp = (FLOAT32)pow(
+ if (num_active_lines_no_ah > FLT_EPSILON) {
+ FLOAT32 avg_thr_exp = (FLOAT32)pow(
2.0f, (const_part_no_ah - red_pe_no_ah) / (INV_RED_EXP_VAL * num_active_lines_no_ah));
redval += (FLOAT32)pow(2.0f, (const_part_no_ah - desired_pe_no_ah) /
(INV_RED_EXP_VAL * num_active_lines_no_ah)) -
diff --git a/encoder/ixheaace_fd_qc_adjthr.c b/encoder/ixheaace_fd_qc_adjthr.c
index d66a765..8e7def0 100644
--- a/encoder/ixheaace_fd_qc_adjthr.c
+++ b/encoder/ixheaace_fd_qc_adjthr.c
@@ -798,7 +798,7 @@ static IA_ERRORCODE iusace_adapt_thr_to_pe(ia_psy_mod_out_data_struct *pstr_psy_
FLOAT32 const_part, const_part_no_ah;
FLOAT32 nactive_lines, nactive_lines_no_ah;
FLOAT32 desired_pe_no_ah;
- FLOAT32 avg_thr_exp, redval;
+ FLOAT32 redval = 0.0f;
WORD32 *ah_flag[2];
WORD32 iteration;
for (WORD32 i = 0; i < 2; i++) {
@@ -818,12 +818,14 @@ static IA_ERRORCODE iusace_adapt_thr_to_pe(ia_psy_mod_out_data_struct *pstr_psy_
no_red_pe = pstr_qs_pe_data->pe;
const_part = pstr_qs_pe_data->const_part;
nactive_lines = pstr_qs_pe_data->num_active_lines;
- avg_thr_exp = (FLOAT32)pow(2.0f, (const_part - no_red_pe) / (INV_RED_EXP_VAL * nactive_lines));
- redval = (FLOAT32)pow(2.0f, (const_part - desired_pe) / (INV_RED_EXP_VAL * nactive_lines)) -
- avg_thr_exp;
- redval = MAX(0.0f, redval);
-
- iusace_reduce_thr(pstr_psy_out, ah_flag, thr_exp, redval, num_channels, chn);
+ if (nactive_lines > FLT_EPSILON) {
+ FLOAT32 avg_thr_exp = (FLOAT32)pow(2.0f, (const_part - no_red_pe) /
+ (INV_RED_EXP_VAL * nactive_lines));
+ redval = (FLOAT32)pow(2.0f, (const_part - desired_pe) / (INV_RED_EXP_VAL * nactive_lines)) -
+ avg_thr_exp;
+ redval = MAX(0.0f, redval);
+ iusace_reduce_thr(pstr_psy_out, ah_flag, thr_exp, redval, num_channels, chn);
+ }
iusace_calc_sfb_pe_data(pstr_qs_pe_data, pstr_psy_out, num_channels, chn);
red_pe = pstr_qs_pe_data->pe;
@@ -834,8 +836,8 @@ static IA_ERRORCODE iusace_adapt_thr_to_pe(ia_psy_mod_out_data_struct *pstr_psy_
pstr_qs_pe_data, ah_flag, pstr_psy_out, num_channels, chn);
desired_pe_no_ah = MAX(desired_pe - (red_pe - red_pe_no_ah), 0);
- if (nactive_lines_no_ah > 0) {
- avg_thr_exp = (FLOAT32)pow(
+ if (nactive_lines_no_ah > FLT_EPSILON) {
+ FLOAT32 avg_thr_exp = (FLOAT32)pow(
2.0f, (const_part_no_ah - red_pe_no_ah) / (INV_RED_EXP_VAL * nactive_lines_no_ah));
redval += (FLOAT32)pow(2.0f, (const_part_no_ah - desired_pe_no_ah) /
(INV_RED_EXP_VAL * nactive_lines_no_ah)) -