Use saturate shift to prevent signed integer overflow in multiple qmfInverseModulation*() functions.

Bug: 145669510
Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc
Change-Id: I4cee10423bc14e3db26de877b5e70701ac3324da
This commit is contained in:
Fraunhofer IIS FDK 2019-10-29 13:10:23 +01:00 committed by Jean-Michel Trivi
parent 9d40b65b15
commit 5357a4411a
1 changed files with 23 additions and 22 deletions

View File

@ -609,9 +609,9 @@ inline static void qmfInverseModulationLP_even(
FIXP_DBL *RESTRICT tImag = pTimeOut + L; FIXP_DBL *RESTRICT tImag = pTimeOut + L;
/* Move input to output vector with offset */ /* Move input to output vector with offset */
scaleValues(&tReal[0], &qmfReal[0], synQmf->lsb, (int)scaleFactorLowBand); scaleValuesSaturate(&tReal[0], &qmfReal[0], synQmf->lsb, scaleFactorLowBand);
scaleValues(&tReal[0 + synQmf->lsb], &qmfReal[0 + synQmf->lsb], scaleValuesSaturate(&tReal[0 + synQmf->lsb], &qmfReal[0 + synQmf->lsb],
synQmf->usb - synQmf->lsb, (int)scaleFactorHighBand); synQmf->usb - synQmf->lsb, scaleFactorHighBand);
FDKmemclear(&tReal[0 + synQmf->usb], (L - synQmf->usb) * sizeof(FIXP_DBL)); FDKmemclear(&tReal[0 + synQmf->usb], (L - synQmf->usb) * sizeof(FIXP_DBL));
/* Dct type-2 transform */ /* Dct type-2 transform */
@ -662,8 +662,8 @@ inline static void qmfInverseModulationLP_odd(
int shift = 0; int shift = 0;
/* Move input to output vector with offset */ /* Move input to output vector with offset */
scaleValues(pTimeOut + M, qmfReal, synQmf->lsb, scaleFactorLowBand); scaleValuesSaturate(pTimeOut + M, qmfReal, synQmf->lsb, scaleFactorLowBand);
scaleValues(pTimeOut + M + synQmf->lsb, qmfReal + synQmf->lsb, scaleValuesSaturate(pTimeOut + M + synQmf->lsb, qmfReal + synQmf->lsb,
synQmf->usb - synQmf->lsb, scaleFactorHighBand); synQmf->usb - synQmf->lsb, scaleFactorHighBand);
FDKmemclear(pTimeOut + M + synQmf->usb, (L - synQmf->usb) * sizeof(FIXP_DBL)); FDKmemclear(pTimeOut + M + synQmf->usb, (L - synQmf->usb) * sizeof(FIXP_DBL));
@ -698,26 +698,27 @@ inline static void qmfInverseModulationHQ(
FIXP_DBL *RESTRICT tImag = pWorkBuffer + L; FIXP_DBL *RESTRICT tImag = pWorkBuffer + L;
if (synQmf->flags & QMF_FLAG_CLDFB) { if (synQmf->flags & QMF_FLAG_CLDFB) {
for (i = 0; i < synQmf->lsb; i++) { for (i = 0; i < synQmf->usb; i++) {
cplxMult(&tImag[i], &tReal[i], scaleValue(qmfImag[i], scaleFactorLowBand), cplxMultDiv2(&tImag[i], &tReal[i], qmfImag[i], qmfReal[i],
scaleValue(qmfReal[i], scaleFactorLowBand), synQmf->t_cos[i], synQmf->t_cos[i], synQmf->t_sin[i]);
synQmf->t_sin[i]);
}
for (; i < synQmf->usb; i++) {
cplxMult(&tImag[i], &tReal[i],
scaleValue(qmfImag[i], scaleFactorHighBand),
scaleValue(qmfReal[i], scaleFactorHighBand), synQmf->t_cos[i],
synQmf->t_sin[i]);
} }
scaleValuesSaturate(&tReal[0], synQmf->lsb, scaleFactorLowBand + 1);
scaleValuesSaturate(&tReal[0 + synQmf->lsb], synQmf->usb - synQmf->lsb,
scaleFactorHighBand + 1);
scaleValuesSaturate(&tImag[0], synQmf->lsb, scaleFactorLowBand + 1);
scaleValuesSaturate(&tImag[0 + synQmf->lsb], synQmf->usb - synQmf->lsb,
scaleFactorHighBand + 1);
} }
if ((synQmf->flags & QMF_FLAG_CLDFB) == 0) { if ((synQmf->flags & QMF_FLAG_CLDFB) == 0) {
scaleValues(&tReal[0], &qmfReal[0], synQmf->lsb, (int)scaleFactorLowBand); scaleValuesSaturate(&tReal[0], &qmfReal[0], synQmf->lsb,
scaleValues(&tReal[0 + synQmf->lsb], &qmfReal[0 + synQmf->lsb], scaleFactorLowBand);
synQmf->usb - synQmf->lsb, (int)scaleFactorHighBand); scaleValuesSaturate(&tReal[0 + synQmf->lsb], &qmfReal[0 + synQmf->lsb],
scaleValues(&tImag[0], &qmfImag[0], synQmf->lsb, (int)scaleFactorLowBand); synQmf->usb - synQmf->lsb, scaleFactorHighBand);
scaleValues(&tImag[0 + synQmf->lsb], &qmfImag[0 + synQmf->lsb], scaleValuesSaturate(&tImag[0], &qmfImag[0], synQmf->lsb,
synQmf->usb - synQmf->lsb, (int)scaleFactorHighBand); scaleFactorLowBand);
scaleValuesSaturate(&tImag[0 + synQmf->lsb], &qmfImag[0 + synQmf->lsb],
synQmf->usb - synQmf->lsb, scaleFactorHighBand);
} }
FDKmemclear(&tReal[synQmf->usb], FDKmemclear(&tReal[synQmf->usb],