microsoft / microsoft/FFmpegInterop
Unmanaged crash when incoming video data has no pixel format
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.4k
- Forks
- 319
- PR merge metrics
- No merged PRs in 30d
Description
I'm writing an app that connects to various RTSP video camera feeds, and every once in a while, a corrupt video stream (which also fails to show on raw ffmpeg or VLC) would not only fail, but also crash my UWP app with an uncatchable memory violation error.
When debugging, I noticed that this error occurred when FFmpeg failed to correctly identify the pixel format for the incoming string, leading the avVideoCodecCtx->pix_fmt set to AV_PIX_FMT_NONE (i.e. -1). When this is passed to sws_getContext in UncompressedVideoSampleProvider::AllocateResources, it spawns the "attempt was made to access invalid memory" error I ultimately get in my C# code.
For now, I've forked the library and added an explicit check, before the call to AllocateResources, which throws an exception (that can be handled by my C# code) that the feed is invalid, and that's a good enough solution for me. However, it might not be the correct general-purpose handling for the library.
I can create a PR for my fix, but I'm guessing you would prefer to fix it some other way. In any case, cleaner error handling (whether via exception or HRESULT) is probably required for these scenarios.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at UncompressedVideoSampleProvider::AllocateResources and inspect the sws_getContext call when avVideoCodecCtx->pix_fmt is AV_PIX_FMT_NONE. Determine how this invalid pixel format should be reported to the C# caller, then verify that the corrupt stream produces a handled error instead of an unmanaged memory violation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- audio-video-rtc, desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100