alexa / avs-device-sdk

An SDK for commercial device makers to integrate Alexa directly into connected products.
https://developer.amazon.com/alexa/alexa-voice-service
Apache License 2.0
1.26k stars 602 forks source link

AndroidSLESMediaQueue::fillBuffer() may coredump #1942

Open xlb767923274 opened 3 years ago

xlb767923274 commented 3 years ago

IMPORTANT: Before you create an issue, please take a look at our Issue Reporting Guide.

Briefly summarize your issue:

avs-device-sdk/MediaPlayer/AndroidSLESMediaPlayer/src/AndroidSLESMediaQueue.cpp

thread1:

          void AndroidSLESMediaQueue::fillAllBuffers(const PlaybackConfiguration& configuration) {
              enqueueSilence(configuration);

              for (; m_index < m_buffers.size(); ++m_index) {
                  m_executor.submit([this]() { fillBuffer(); });
              }
              m_index = 0;
          }

thread2:

    void AndroidSLESMediaQueue::fillBuffer() {
            .......
            auto index = m_index;
            m_index = (m_index + 1) % NUMBER_OF_BUFFERS;
            ......
            std::tie(status, wordsRead) = m_decoder->read(m_buffers[index].data(), m_buffers[index].size());
            .....
    }

m_index is a global var m_buffers.size() = NUMBER_OF_BUFFERS = 4; so, index should be 0 - 3;

but in thread1, m_index's max value is NUMBER_OF_BUFFERS + 1 (possibilities) and at this time, thread2 would get a m_buffers[4], it's a invalid memory;

What is the expected behavior?

What behavior are you observing?

coredump

Provide the steps to reproduce the issue, if applicable:

interaction with alexa in android system

Tell us about your environment:

What version of the AVS Device SDK are you using?

  <x.y.z>

1.22.0

Tell us what hardware you're using:

Tell us about your OS (Type & version):

womw commented 3 years ago

Hi thanks for posting @xlb767923274 We're currently investigating this bug

xlb767923274 commented 3 years ago

Hi thanks for posting @xlb767923274 We're currently investigating this bug

other question :

  1. At this file(AndroidSLESMediaQueue.cpp), the ‘m_playedWords’ are not accurate, 1.1. It has Enqueued a silense buffer ( size = 4? ) at first time, this buffer's size hasn't count into the array(m_bufferSizes ); but at callback function by this silense buffer, m_playedWords add a size by 'm_decoder->read()' 1.2. From MSP certification report PlaybackStopped FAIL [INCORRECT_OFFSET_TOO_LOW] 9427(Expected:19809) if fillBuffer() blocked at m_decoder->read() because of network delay, then the queueCallback() will blocked at executor 's task queue, the m_playedWords is smaller than actual value; 1.3. Is it possible to get the offset through GetPosition() from libopenSLES? 1.4. this affects all audioplayer's events to the cloud;

  2. AndroidSLESMediaQueue::fillAllBuffers():

      void AndroidSLESMediaQueue::fillAllBuffers(const PlaybackConfiguration& configuration) {
              enqueueSilence(configuration);  **// Enqueue  a buffer**
    
              for (; m_index < m_buffers.size(); ++m_index) {  //  **// Enqueue m_buffers.size() buffer**
                  m_executor.submit([this]() { fillBuffer(); });
              }
              m_index = 0;
          }

    so at this function, enqueued buffer total size is NUMBER_OF_BUFFERS +1, that may be result in 'SL_RESULT_BUFFER_INSUFFICIENT' when Enqueue(),

     _If the maximum number of buffers specified in the 
    SLDataLocator_BufferQueue structure used as the data source when 
    creating the media object using the CreateAudioPlayer or 
    CreateMidiPlayer method has been reached, the buffer is not added to 
    the buffer queue and SL_RESULT_BUFFER_INSUFFICIENT is returned. At 
    this point the client should wait until it receives a callback notification 
    for a buffer completion at which time it can enqueue the buffer._

    But the code did not handle the return value of SL_RESULT_BUFFER_INSUFFICIENT, but directly returned "onPlaybackError" to the cloud,

It's Too difficult to pass MSP Certification for alexa android version!! Has any other manufacturer passed the MSP certification in Android version?