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

obs-webrtc: Add null terminator to codec array #10621

Merged
merged 1 commit into from May 4, 2024

Conversation

kc5nra
Copy link
Collaborator

@kc5nra kc5nra commented Apr 29, 2024

This fixes an issue where when the MAX_CODECS length was equal to the amount of supported codecs (3), it would leave the list without a null terminator and crash when iterating over the elements.

Description

Addresses a bug where a non-null terminated list of strings was iterated over into invalid memory

Motivation and Context

Crashes on some machines depending on if the memory layout had a null accidentally after the list.

How Has This Been Tested?

Tested on Mac and Windows, no longer crashes in release mode.

Types of changes

Bug fix

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.

Copy link
Contributor

@Sean-Der Sean-Der left a comment

Choose a reason for hiding this comment

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

Works great for me!

Copy link
Member

@RytoEX RytoEX left a comment

Choose a reason for hiding this comment

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

Wrap the commit message body at 72 characters, not 60.

Is this a problem for all other const char *something[] instances across the codebase? Is that type even appropriate here? Should this just be a std vector/array or an enum (as it is elsewhere in the codebase) instead?

I'm fine getting a crash fixed quickly and merging this as-is (after fixing nits). However, I feel like this is not our first problem with this implementation, and I think a few reviewers have expressed discontent with it.

@kc5nra
Copy link
Collaborator Author

kc5nra commented Apr 29, 2024

Wrap the commit message body at 72 characters, not 60.

Is this a problem for all other const char *something[] instances across the codebase? Is that type even appropriate here? Should this just be a std vector/array or an enum (as it is elsewhere in the codebase) instead?

I'm fine getting a crash fixed quickly and merging this as-is (after fixing nits). However, I feel like this is not our first problem with this implementation, and I think a few reviewers have expressed discontent with it.

It would be an API breaking change to address it differently.

        info.get_supported_video_codecs = [](void *) -> const char ** {
		return video_codecs;
	};
	info.get_supported_audio_codecs = [](void *) -> const char ** {
		return audio_codecs;
	};

So the services getters would have to change to change the type

This fixes an issue where, when the MAX_CODECS length was equal to the
amount of supported codecs (3), it would leave the list without a null
terminator and crash when iterating over the elements.
@kc5nra kc5nra force-pushed the john/fix-whip-services-codec-list branch from f0acc78 to 09e8ad0 Compare April 29, 2024 23:01
@kc5nra
Copy link
Collaborator Author

kc5nra commented Apr 29, 2024

But yes, it would be a problem for all the API functions that rely on (*next_item == 0) for determining last element

@RytoEX
Copy link
Member

RytoEX commented Apr 29, 2024

Wrap the commit message body at 72 characters, not 60.
Is this a problem for all other const char *something[] instances across the codebase? Is that type even appropriate here? Should this just be a std vector/array or an enum (as it is elsewhere in the codebase) instead?
I'm fine getting a crash fixed quickly and merging this as-is (after fixing nits). However, I feel like this is not our first problem with this implementation, and I think a few reviewers have expressed discontent with it.

It would be an API breaking change to address it differently.

For what it's worth, I'm not saying to change the return type there. You can build the string however you like (see rtmp-common). I'm suggesting that relying on a raw const char *something[] here and doing strcmp calls is perhaps not ideal, but that is outside the scope of this PR.

But yes, it would be a problem for all the API functions that rely on (*next_item == 0) for determining last element

If there are other places where this is problematic, we would welcome fixes for those.

@kc5nra
Copy link
Collaborator Author

kc5nra commented Apr 29, 2024

Makes sense - I think I just read your first message too fast, my fault! I'll ponder a better approach for this service in another PR

Thanks!

@kc5nra kc5nra requested a review from RytoEX April 30, 2024 00:09
@RytoEX RytoEX added the Bug Fix Non-breaking change which fixes an issue label May 4, 2024
@RytoEX RytoEX added this to the OBS Studio (Next Version) milestone May 4, 2024
@tt2468 tt2468 merged commit 627308b into obsproject:master May 4, 2024
14 checks passed
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.

None yet

5 participants