Skip to content

Maximum chunk size assertion in videoio's AVI container implementation appears to be incorrect. #11126

Closed
@anthonytw

Description

System information (version)
  • OpenCV => 3.4.1
  • Operating System / Platform => Ubuntu Linux 17.10 64-bit
  • Compiler => clang-5.0
Detailed description

The AVI container implementation in the videoio module appears, to me, to have a bug. In file modules/videoio/src/container_avi.cpp the following function is defined:

std::vector<char> AVIReadContainer::readFrame(frame_iterator it)
{
    m_file_stream->seekg(it->first);

    RiffChunk chunk;
    *(m_file_stream) >> chunk;
    CV_Assert(chunk.m_size <= 0xFFFF);   // <--- ATW: Bug?

    std::vector<char> result;

    result.reserve(chunk.m_size);
    result.resize(chunk.m_size);

    m_file_stream->read(&(result[0]), chunk.m_size); // result.data() failed with MSVS2008

    return result;
}

Notice the assertion: CV_Assert(chunk.m_size <= 0xFFFF);. I was running into the issue where I was unable to open an MJPG video with the VideoCapture class after writing it with the VideoWriter class. The video seems perfectly fine, and when I remove this assertion the software works as expected.

Why is this assertion present? Has this chunk size limitation possibly been increased or removed in newer implementations? It seems this assertion either needs to be updated with a larger maximum chunk size or removed all together, but I'm not sure which. Alternatively, if this is a real limit then there may be a bug in the code that writes the AVI videos, since it seems to be using chunk sizes that trigger this assertion when the videos are read back in.

Steps to reproduce

No code. You need to get (un)lucky and generate a video that includes large chunks. I can provide a video if helpful, but this seems like more of an API / specification technicality.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions