Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libobs/media-io: Avoid allocating frame memory if size is zero #11803

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RytoEX
Copy link
Member

@RytoEX RytoEX commented Jan 31, 2025

Description

It is possible that size can still be zero after the preceding loop. If that happens, and bmalloc is called with 0 as its argument, OBS will crash as intended with OBS Studio 31. Avoid crashing by not allocating memory for a frame with a size of zero.

Motivation and Context

See the crash in:

If there's a better place to do this check, I'm open to alternatives.

How Has This Been Tested?

Compiled and ran locally on Windows 11 with a Video Capture Device added.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

It is possible that size can still be zero after the preceding loop. If
that happens, and bmalloc is called with 0 as its argument, OBS will
crash as intended with OBS Studio 31. Avoid crashing by not allocating
memory for a frame with a size of zero.
@RytoEX RytoEX added the Bug Fix Non-breaking change which fixes an issue label Jan 31, 2025
@RytoEX RytoEX added this to the OBS Studio 31.0 milestone Jan 31, 2025
@RytoEX RytoEX requested a review from tt2468 January 31, 2025 19:24
@RytoEX RytoEX self-assigned this Jan 31, 2025
@tt2468
Copy link
Member

tt2468 commented Jan 31, 2025

I think my primary worry here would be that video_frame_init is a void return, so we might not actually be fixing any issues, rather pushing the undefined behavior to somewhere else.

@RytoEX
Copy link
Member Author

RytoEX commented Jan 31, 2025

I think my primary worry here would be that video_frame_init is a void return, so we might not actually be fixing any issues, rather pushing the undefined behavior to somewhere else.

video_frame_init can already early return:

if (!frame)
return;

That said, I'm open to alternatives, but we intentionally crash if bmalloc(0) is called now, so we should really try to avoid calling bmalloc(0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix Non-breaking change which fixes an issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants