[FFmpeg-trac] #7094(avformat:new): Assertion in AVIO fill_buffer

FFmpeg trac at avcodec.org
Tue Mar 20 04:48:33 EET 2018


#7094: Assertion in AVIO fill_buffer
-------------------------------------+-------------------------------------
             Reporter:  redeemarr    |                     Type:  defect
               Status:  new          |                 Priority:  normal
            Component:  avformat     |                  Version:  git-
             Keywords:  avio,        |  master
  abort, crash                       |               Blocked By:
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------
 It happens sometimes while demuxing mpegts stream using custom IO
 operations via AVIOContext, assertion fails in function 'fill_buffer' in
 aviobuf.c:
 av_assert0(len >= s->orig_buffer_size);
 Seems like something goes wrong when AVIOContext decides to reduce it's
 internal buffer size.

 This issue can be easily reproduced in my case, when
 AVFormatContext.probesize equals initial buffer size for AVIOContext.
 Sample code to reproduce:
 {{{#!c++

 int read_handler(void* opaque, uint8_t* dst, int dst_size)
 {
         bytes_t* input = (bytes_t*)opaque;
         size_t available = input->size();
         size_t size = available < dst_size ? available : dst_size;
         if (size > 0)
         {
                 memcpy(dst, input->data(), size);
                 input->erase(input->begin(), input->begin() + size);
         }
         return size > 0 ? size : AVERROR_EOF;
 }

 void test_avio(char const* path)
 {
         std::ifstream ifs(path, std::ios::binary);
         ifs.seekg(0, std::ios::end);
         size_t size = ifs.tellg();
         ifs.seekg(0, std::ios::beg);

         std::vector<char> input(size);
         ifs.read(input.data(), input.size());

         AVInputFormat* m_format = av_find_input_format("mpegts");
         AVFormatContext* m_fc = avformat_alloc_context();

         size_t buffer_size = 16 * 1024;
         uint8_t* avio_buffer = (uint8_t*)av_malloc(buffer_size +
 FF_INPUT_BUFFER_PADDING_SIZE);

         m_fc = avformat_alloc_context();
         m_fc->probesize = buffer_size;
         m_fc->pb = avio_alloc_context(avio_buffer, buffer_size, 0, &input,
 &read_handler, NULL, NULL);
         m_fc->pb->seekable = 0;
         m_fc->pb->write_flag = 0;

         int err = avformat_open_input(&m_fc, NULL, m_format, NULL);

         err = avformat_find_stream_info(m_fc, NULL); // In this case it
 fails even at this point

         // ...
 }

 }}}

--
Ticket URL: <https://trac.ffmpeg.org/ticket/7094>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list