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

Commit f20dcbcb authored by James Dong's avatar James Dong Committed by Android (Google) Code Review
Browse files

Merge "libstagefright: Add error handling in AMRNB deooder"

parents e3f07562 14e974af
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -14,6 +14,10 @@
 * limitations under the License.
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "AMRNBDecoder"
#include <utils/Log.h>

#include "AMRNBDecoder.h"

#include "gsmamr_dec.h"
@@ -154,18 +158,24 @@ status_t AMRNBDecoder::read(
    const uint8_t *inputPtr =
        (const uint8_t *)mInputBuffer->data() + mInputBuffer->range_offset();

    size_t numBytesRead =
    int32_t numBytesRead =
        AMRDecode(mState,
          (Frame_Type_3GPP)((inputPtr[0] >> 3) & 0x0f),
          (UWord8 *)&inputPtr[1],
          static_cast<int16_t *>(buffer->data()),
          MIME_IETF);

    if (numBytesRead == -1 ) {
        LOGE("PV AMR decoder AMRDecode() call failed");
        buffer->release();
        buffer = NULL;
        return ERROR_MALFORMED;
    }
    ++numBytesRead;  // Include the frame type header byte.

    buffer->set_range(0, kNumSamplesPerFrame * sizeof(int16_t));

    if (numBytesRead > mInputBuffer->range_length()) {
    if (static_cast<size_t>(numBytesRead) > mInputBuffer->range_length()) {
        // This is bad, should never have happened, but did. Abort now.

        buffer->release();