aboutsummaryrefslogtreecommitdiffstats
path: root/libAACdec
diff options
context:
space:
mode:
authorFraunhofer IIS FDK <audio-fdk@iis.fraunhofer.de>2019-10-29 13:05:02 +0100
committerJean-Michel Trivi <jmtrivi@google.com>2019-12-27 08:51:59 -0800
commit07b5fd99418373e7c622030735bd47a0b153a9ec (patch)
treea5a86710d1604edea5dabf4130832e9d08d3870d /libAACdec
parent77e652f76694102b9c6499d5a2209ca0bf44e0c3 (diff)
downloadfdk-aac-07b5fd99418373e7c622030735bd47a0b153a9ec.tar.gz
fdk-aac-07b5fd99418373e7c622030735bd47a0b153a9ec.tar.bz2
fdk-aac-07b5fd99418373e7c622030735bd47a0b153a9ec.zip
Use one additional bit headroom to prevent signed integer overflow in BuildAdaptiveExcitation().
Bug: 145666984 Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I5c881238562c3d9f7cd8d77a8c52f7231126587f
Diffstat (limited to 'libAACdec')
-rw-r--r--libAACdec/src/usacdec_acelp.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/libAACdec/src/usacdec_acelp.cpp b/libAACdec/src/usacdec_acelp.cpp
index 1ac8c9f..a8dadc0 100644
--- a/libAACdec/src/usacdec_acelp.cpp
+++ b/libAACdec/src/usacdec_acelp.cpp
@@ -465,7 +465,9 @@ void BuildAdaptiveExcitation(
/* Note: code[L_SUBFR] and exc2[L_SUBFR] share the same memory!
If exc2[i] is written, code[i] will be destroyed!
*/
-#define SF (SF_CODE + SF_GAIN_C + 1 - SF_EXC)
+#define SF_HEADROOM (1)
+#define SF (SF_CODE + SF_GAIN_C + 1 - SF_EXC - SF_HEADROOM)
+#define SF_GAIN_P2 (SF_GAIN_P - SF_HEADROOM)
int i;
FIXP_DBL tmp, cpe, code_smooth_prev, code_smooth;
@@ -477,8 +479,8 @@ void BuildAdaptiveExcitation(
cpe = (period_fac >> (2 - SF_PFAC)) + FL2FXCONST_DBL(0.25f);
/* u'(n) */
- tmp = fMultDiv2(*exc, gain_pit) << (SF_GAIN_P + 1); /* v(0)*g_p */
- *exc++ = tmp + (fMultDiv2(code[0], gain_code) << SF);
+ tmp = fMultDiv2(*exc, gain_pit) << (SF_GAIN_P2 + 1); /* v(0)*g_p */
+ *exc++ = (tmp + (fMultDiv2(code[0], gain_code) << SF)) << SF_HEADROOM;
/* u(n) */
code_smooth_prev = fMultDiv2(*code++, gain_code_smoothed)
@@ -487,15 +489,15 @@ void BuildAdaptiveExcitation(
code_smooth = fMultDiv2(code_i, gain_code_smoothed) << SF; /* c(1) * g_sc */
tmp += code_smooth_prev; /* tmp = v(0)*g_p + c(0)*g_sc */
cpe_code_smooth = fMultDiv2(cpe, code_smooth);
- *exc2++ = tmp - cpe_code_smooth;
+ *exc2++ = (tmp - cpe_code_smooth) << SF_HEADROOM;
cpe_code_smooth_prev = fMultDiv2(cpe, code_smooth_prev);
i = L_SUBFR - 2;
do /* ARM926: 22 cycles per iteration */
{
/* u'(n) */
- tmp = fMultDiv2(*exc, gain_pit) << (SF_GAIN_P + 1);
- *exc++ = tmp + (fMultDiv2(code_i, gain_code) << SF);
+ tmp = fMultDiv2(*exc, gain_pit) << (SF_GAIN_P2 + 1);
+ *exc++ = (tmp + (fMultDiv2(code_i, gain_code) << SF)) << SF_HEADROOM;
/* u(n) */
tmp += code_smooth; /* += g_sc * c(i) */
tmp -= cpe_code_smooth_prev;
@@ -503,16 +505,17 @@ void BuildAdaptiveExcitation(
code_i = *code++;
code_smooth = fMultDiv2(code_i, gain_code_smoothed) << SF;
cpe_code_smooth = fMultDiv2(cpe, code_smooth);
- *exc2++ = tmp - cpe_code_smooth; /* tmp - c_pe * g_sc * c(i+1) */
+ *exc2++ = (tmp - cpe_code_smooth)
+ << SF_HEADROOM; /* tmp - c_pe * g_sc * c(i+1) */
} while (--i != 0);
/* u'(n) */
- tmp = fMultDiv2(*exc, gain_pit) << (SF_GAIN_P + 1);
- *exc = tmp + (fMultDiv2(code_i, gain_code) << SF);
+ tmp = fMultDiv2(*exc, gain_pit) << (SF_GAIN_P2 + 1);
+ *exc = (tmp + (fMultDiv2(code_i, gain_code) << SF)) << SF_HEADROOM;
/* u(n) */
tmp += code_smooth;
tmp -= cpe_code_smooth_prev;
- *exc2++ = tmp;
+ *exc2++ = tmp << SF_HEADROOM;
return;
}