Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0df2c6ed authored by Andre Eisenbach's avatar Andre Eisenbach
Browse files

A2DP: Protect against division-by-zero error in bitpool calculation

If the encoder parameters have not been configured correctly before the
SBC encoder is initialized, a division-by-zero can occur resulting in a
SIGFPE.

Bug: 16902125
Change-Id: Ie4c6715b6b374a2d62fcfa0a1a99d40c689d0e2a
parent 3970c0da
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -1874,7 +1874,7 @@ static void btif_media_task_enc_update(BT_HDR *p_msg)
    tBTIF_MEDIA_UPDATE_AUDIO * pUpdateAudio = (tBTIF_MEDIA_UPDATE_AUDIO *) p_msg;
    SBC_ENC_PARAMS *pstrEncParams = &btif_media_cb.encoder;
    UINT16 s16SamplingFreq;
    SINT16 s16BitPool;
    SINT16 s16BitPool = 0;
    SINT16 s16BitRate;
    SINT16 s16FrameLen;
    UINT8 protect = 0;
@@ -1904,6 +1904,16 @@ static void btif_media_task_enc_update(BT_HDR *p_msg)

        do
        {
            if (pstrEncParams->s16NumOfBlocks == 0 || pstrEncParams->s16NumOfSubBands == 0
                || pstrEncParams->s16NumOfChannels == 0)
            {
                APPL_TRACE_ERROR("btif_media_task_enc_update() - Avoiding division by zero...");
                APPL_TRACE_ERROR("btif_media_task_enc_update() - block=%d, subBands=%d, channels=%d",
                    pstrEncParams->s16NumOfBlocks, pstrEncParams->s16NumOfSubBands,
                    pstrEncParams->s16NumOfChannels);
                break;
            }

            if ((pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) ||
                (pstrEncParams->s16ChannelMode == SBC_STEREO) )
            {