From 40d2a1d8b055ebe17b67195029029ecdc5bc3268 Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 20 Sep 2019 13:58:23 +0200 Subject: Avoid integer overflows with pseudoLR in CAacDecoder_DecodeFrame(). Bug: 131430997 Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I5c83d72b5c0f4cd1569b648f102c8c549a7a6ac2 --- libAACdec/src/aacdecoder.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'libAACdec') diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp index b15fc80..6b5a86c 100644 --- a/libAACdec/src/aacdecoder.cpp +++ b/libAACdec/src/aacdecoder.cpp @@ -3388,7 +3388,8 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame( * LR) */ if ((aacChannels == 2) && bsPseudoLr) { int i, offset2; - const FIXP_SGL invSqrt2 = FL2FXCONST_SGL(0.707106781186547f); + const FIXP_SGL invSqrt2 = + FL2FXCONST_SGL(0.353553390593273f); /* scaled by -1 */ FIXP_PCM *pTD = pTimeData; offset2 = timeDataChannelOffset; @@ -3399,11 +3400,14 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame( L = fMult(L, invSqrt2); R = fMult(R, invSqrt2); #if (SAMPLE_BITS == 16) - pTD[0] = FX_DBL2FX_PCM(fAddSaturate(L + R, (FIXP_DBL)0x8000)); - pTD[offset2] = FX_DBL2FX_PCM(fAddSaturate(L - R, (FIXP_DBL)0x8000)); + pTD[0] = (FIXP_SGL)SATURATE_RIGHT_SHIFT(L + R + (FIXP_DBL)(1 << 14), + 15, FRACT_BITS); + pTD[offset2] = (FIXP_SGL)SATURATE_RIGHT_SHIFT( + L - R + (FIXP_DBL)(1 << 14), 15, FRACT_BITS); #else - pTD[0] = FX_DBL2FX_PCM(L + R); - pTD[offset2] = FX_DBL2FX_PCM(L - R); + pTD[0] = SATURATE_LEFT_SHIFT(FX_DBL2FX_PCM(L + R), 1, DFRACT_BITS); + pTD[offset2] = + SATURATE_LEFT_SHIFT(FX_DBL2FX_PCM(L - R), 1, DFRACT_BITS); #endif pTD++; } -- cgit v1.2.3