Fix for the Divide-by-zero in ixheaace_spectral_change
These changes handle the Divide-by-zero runtime error
reported when the energy value calculated is zero.
This is resolved by adding a non zero value to the
energy if it becomes zero.
Bug: ossFuzz: 61974
Test: poc in bug
diff --git a/encoder/ixheaace_sbr_tran_det.c b/encoder/ixheaace_sbr_tran_det.c
index cf9bce4..a18ba9e 100644
--- a/encoder/ixheaace_sbr_tran_det.c
+++ b/encoder/ixheaace_sbr_tran_det.c
@@ -52,7 +52,7 @@
FLOAT32 pos_wt = (0.5f - (FLOAT32)len1 / (FLOAT32)(len1 + len2));
pos_wt = 1.0f - 4.0f * pos_wt * pos_wt;
- if ((is_ld_sbr) && (total_energy == 0.0f)) {
+ if (total_energy < SBR_EPS) {
*ptr_delta = 0.0f;
return IA_NO_ERROR;
}
@@ -72,8 +72,14 @@
for (i = border; i < stop; i++) {
energy_2[j] += ptr_energies[i][j];
}
- delta = (float)fabs(log(energy_2[j] / energy_1[j] * len_ratio));
- delta_sum += (float)(sqrt((energy_1[j] + energy_2[j]) / total_energy) * delta);
+ if (energy_1[j] <= EPS) {
+ energy_1[j] = (FLOAT32)len1;
+ }
+ if (energy_2[j] <= EPS) {
+ energy_2[j] = (FLOAT32)len2;
+ }
+ delta = (FLOAT32)fabs(log((energy_2[j] / energy_1[j]) * len_ratio));
+ delta_sum += (FLOAT32)(sqrt((energy_1[j] + energy_2[j]) / total_energy) * delta);
}
*ptr_delta = delta_sum * pos_wt;