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

frontend: Fix crashes caused by scene collections with empty internal name #11735

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

PatTheMav
Copy link
Member

@PatTheMav PatTheMav commented Jan 17, 2025

Description

Prevents API clients against creating scene collections without a name, while also handling the possible case of a malformed scene collection gracefully.

Motivation and Context

OBS Studio itself does not allow users to create scene collections without a name, but the checks were not added to the internal API as well. Thus API clients were able to limbo right underneath that requirement.

This PR adds two changes:

  1. Adds a check against providing an empty name for a new scene collection.
  2. Adds a fallback to use the scene collection's filename stem as a collection name if a malformed collection is present in the file system.

This should prevent new malformed scene collections to be created by API clients but also protect users against having their OBS Studio instance crash over such malformed collections.

Note

A malformed scene collection will automatically be converted into a well-formed one once OBS Studio saves the current scene collection, as the fallback name will be written into the collection.

Tip

C++ Moment

Because collectionName is a glvalue, the code uses std::move to allow C++ to pilfer the contents of it when initialising candidateName (turning collectionName into an xvalue), as it will not be used by anything else within the loop body after that assignment.

That's also the reason why collectionName is not marked as const, because pilfering requires the ability to modify the contents of it (setting its internal string pointer to nullptr). If it were const, C++ would be forced to make a copy.

Fixes #11609

How Has This Been Tested?

Tested with a scene collection that has an empty name and another collection that has no name key in its collection.

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.

Empty names for scene collections are not allowed, but this constraint
is only enforced by UI code during text input.

Thus frontend API users are able to create valid scene collections with
empty names which will lead to later possible crashes as the scene
collection is malformed.

As the frontend API uses the related function CreateNewSceneCollection
which handles exceptions by this method, no crashes should occur when
an empty string is provided by an API caller.
If - for some reason - the name in a scene collection is empty (or
the key doesn't even exist), use the filename stem as a fallback name.

This ensures that the scene collection entry in the cache has a valid
non-empty name.

Using an std::string allows the use of its "empty" method to check for
this otherwise invalid state of the collection data.
@RytoEX
Copy link
Member

RytoEX commented Jan 17, 2025

@Penwy from #11609.

@RytoEX RytoEX added this to the OBS Studio 31.0 milestone Jan 17, 2025
@RytoEX RytoEX self-assigned this Jan 17, 2025
@RytoEX RytoEX added the Bug Fix Non-breaking change which fixes an issue label Jan 17, 2025
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.

Seems fine. OBS no longer crashes when the file from #11609 is present in the scenes folder or when actively switching to it.

@RytoEX RytoEX merged commit 1baa461 into obsproject:master Jan 17, 2025
14 checks passed
@PatTheMav PatTheMav deleted the fix-empty-scenecollection-name branch January 17, 2025 23:03
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.

Crash when loading scene collection with empty name
2 participants