Skip to content

Commit 27bd8da

Browse files
committed
stagefright aacenc: Avoid overflows when calculating normFactor
normFactor is calculated using the saturating L_add function, but if the value added (*psfbPeFactors) is negative, the sum can end up negative. *psfbPeFactors can end up negative if redThrExp is less than *psfbNActiveLines. In cases where *psfbPeFactors ended up negative, normFactor became INT_MIN, causing division by zero later. Change-Id: I00c852e457b22f7eef4d6ed1887629828057206b
1 parent 23d3628 commit 27bd8da

File tree

1 file changed

+1
-1
lines changed
  • media/libstagefright/codecs/aacenc/src

1 file changed

+1
-1
lines changed

media/libstagefright/codecs/aacenc/src/adj_thr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ static void correctThresh(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
437437
for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {
438438
Word32 redThrExp = thrExp[ch][sfbGrp+sfb] + redVal;
439439

440-
if (((*pahFlag < AH_ACTIVE) || (deltaPe > 0)) && (redThrExp > 0) ) {
440+
if (((*pahFlag < AH_ACTIVE) || (deltaPe > 0)) && (redThrExp > 0) && (redThrExp >= *psfbNActiveLines)) {
441441

442442
*psfbPeFactors = (*psfbNActiveLines) * (0x7fffffff / redThrExp);
443443
normFactor = L_add(normFactor, *psfbPeFactors);

0 commit comments

Comments
 (0)