Skip to content

media-playback: Fix possible crash on startup#12094

Merged
RytoEX merged 1 commit intoobsproject:masterfrom
jeiea:fix/startup-nullptr
May 6, 2025
Merged

media-playback: Fix possible crash on startup#12094
RytoEX merged 1 commit intoobsproject:masterfrom
jeiea:fix/startup-nullptr

Conversation

@jeiea
Copy link
Contributor

@jeiea jeiea commented Apr 28, 2025

Description

Newly added frame width/height check crash if the frame is not given.

We can move the width/height check after other precondition checks.

Motivation and Context

I tested the master branch on my machine, and encountered the following.

crash

How Has This Been Tested?

My local windows 11.

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.

Frame width/height check crash if the frame is not given.

We can reorder width/height check after other precondition checks.
@RytoEX RytoEX requested review from Lain-B and RytoEX April 28, 2025 21:00
@RytoEX RytoEX self-assigned this Apr 28, 2025
@RytoEX
Copy link
Member

RytoEX commented Apr 28, 2025

It seems that on load/play (or end?) of playing an audio file, mp_media_next_video is called and d->frame is NULL.

	obs-ffmpeg.dll!mp_media_next_video(mp_media * m, bool preload) Line 383	C
	obs-ffmpeg.dll!mp_media_reset(mp_media * m) Line 593	C
	obs-ffmpeg.dll!mp_media_thread(mp_media * m) Line 748	C
	obs-ffmpeg.dll!mp_media_thread_start(void * opaque) Line 840	C

An audio file will end up in the early return at Line 400:

if (!preload) {
if (!mp_media_can_play_frame(m, d))
return;
d->frame_ready = false;
if (!m->v_cb)
return;
} else if (!d->frame_ready) {
return;
}

Thus, moving this frame width/height checks after that resolves that issue, and avoids adding a nullptr check for f. I'm not sure if we should add the nullptr check anyway, but that can be discussed separately. We could also move this block further down to right before the if (preload) { section at the end of the function. @Lain-B ?

@RytoEX RytoEX added the Bug Fix Non-breaking change which fixes an issue label Apr 28, 2025
@RytoEX RytoEX added this to the OBS Studio 31.1 milestone Apr 28, 2025
Copy link
Collaborator

@Lain-B Lain-B left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way is fine in my opinion. This is probably fine too.

@Lain-B
Copy link
Collaborator

Lain-B commented May 4, 2025

For additional clarification, the check just needs to be after the:

	} else if (!d->frame_ready) {

check. That will filter out any invalid pointer usage.

@RytoEX
Copy link
Member

RytoEX commented May 6, 2025

For additional clarification, the check just needs to be after the:

	} else if (!d->frame_ready) {

check. That will filter out any invalid pointer usage.

Yeah, I'd figured out as much while testing this PR. We could move the check later to just before we assign width and height, but this is fine.

@RytoEX RytoEX linked an issue May 6, 2025 that may be closed by this pull request
@RytoEX RytoEX merged commit 22c4e11 into obsproject:master May 6, 2025
15 checks passed
@RytoEX RytoEX mentioned this pull request Jun 27, 2025
6 tasks
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.

Segmentation fault when playing an MP3 with a media source

3 participants