[PR #4194] Fix crash related to unparseable/invalid media resource paths #25686

Open
opened 2026-01-31 09:11:07 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/4194

State: closed
Merged: Yes


Summary of the Pull Request

WT crashes when an unparseable/invalid backgroundImage resource path is provided in profiles.json. This PR averts the crash by the validating and correcting backgroundImage resource paths as a part of the _ValidateSettings() function in CascadiaSettings. _ValidateSettings() is run on start up and any time profiles.json is changed, so a user can not change a file path and avoid the validation step.

When a bad backgroundImage resource path is detected this warning screen is presented:
warning

References

#4002 which identified a consistent repro for the crash

PR Checklist

Detailed Description of the Pull Request / Additional comments

To validate the resource, the a Windows::Foundation::Uri object is constructed with the path, the ctor will throw if the resource path is invalid. Whether or not this validation method is robust enough is a subject worth review. The correction method for when a bad resource path is detected is to reset the std::optional<winrt::hstring> holding the file path.

The text in the warning display was cribbed from the text used when an invalid colorScheme is used. Whether or not the case of a bad background image file path warrants a warning display is a subject worth review.

Validation Steps Performed

Ensured the repro steps in #4002 did not trigger a crash. Additionally some potential backdoor paths to a crash were tested:

  • Deleting the file of a validated background image file path
  • Changing the actual file name of a validated background image file path
  • Replacing the file of a validated background image file path with a non-image file (of the same name)
  • Using a non-image file as a background image

In all the above cases WT does not crash, and instead defaults to the background color specified in the profile's colorScheme. This PR does not implement this recovery behavior (existing error catching code does).

**Original Pull Request:** https://github.com/microsoft/terminal/pull/4194 **State:** closed **Merged:** Yes --- <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request WT crashes when an unparseable/invalid `backgroundImage` resource path is provided in `profiles.json`. This PR averts the crash by the validating and correcting `backgroundImage` resource paths as a part of the `_ValidateSettings()` function in `CascadiaSettings`. `_ValidateSettings()` is run on start up and any time `profiles.json` is changed, so a user can not change a file path and avoid the validation step. When a bad `backgroundImage` resource path is detected this warning screen is presented: <img width="425" alt="warning" src="https://user-images.githubusercontent.com/28279285/72232739-e2c28280-3577-11ea-9865-ced6211dae0e.PNG"> <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References #4002 which identified a consistent repro for the crash <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #2329 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Requires documentation to be updated * [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #2329 <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments To validate the resource, the a [`Windows::Foundation::Uri`](https://docs.microsoft.com/en-us/uwp/api/Windows.Foundation.Uri) object is constructed with the path, the ctor will throw if the resource path is invalid. Whether or not this validation method is robust enough is a subject worth review. The correction method for when a bad resource path is detected is to reset the `std::optional<winrt::hstring>` holding the file path. The text in the warning display was cribbed from the text used when an invalid `colorScheme` is used. Whether or not the case of a bad background image file path warrants a warning display is a subject worth review. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Ensured the repro steps in #4002 did not trigger a crash. Additionally some potential backdoor paths to a crash were tested: - Deleting the file of a validated background image file path - Changing the actual file name of a validated background image file path - Replacing the file of a validated background image file path with a non-image file (of the same name) - Using a non-image file as a background image In all the above cases WT does not crash, and instead defaults to the background color specified in the profile's `colorScheme`. This PR does not implement this recovery behavior (existing error catching code does).
claunia added the pull-request label 2026-01-31 09:11:07 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#25686