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

Fix crash related to unparseable/invalid media resource paths #4194

Merged
merged 6 commits into from
Jan 17, 2020

Conversation

mkitzan
Copy link
Contributor

@mkitzan mkitzan commented Jan 13, 2020

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).

@mkitzan mkitzan changed the title Fix crash related to unparseable/invalid background image Fix crash related to unparseable/invalid background image file path Jan 13, 2020
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me, but for some reason I have it in my head that the background image could also be a URL to an image on the web. Was that scenario ever possible, and does it still work with this?

I know there are some people who are also using ms-appdata: paths as their background image, does that still work as well?

@zadjii-msft zadjii-msft added Area-Settings Issues related to settings and customizability, for console or terminal Product-Terminal The new Windows Terminal. labels Jan 13, 2020
@mkitzan
Copy link
Contributor Author

mkitzan commented Jan 13, 2020

Good catch, URLs and ms-appdata/ms-appx paths fail under this scheme. I'll add a check to validate the image path as an URI.

This seems like a good method of validating resource paths.
@mkitzan
Copy link
Contributor Author

mkitzan commented Jan 13, 2020

@zadjii-msft, I found a pretty clean way of validating resource paths. By constructing a Windows::Foundation::Uri object with the path, the ctor will throw if the path is invalid.

(the build failure seems to be due to some anomalous behavior unrelated to this PR)

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

Just a minor issue. Other than that, I think it's good. Thanks!

<data name="InvalidBackgroundImage" xml:space="preserve">
<value>Found a profile with an invalid "backgroundImage". Defaulting that profile to have no background image. Make sure that when setting a "backgroundImage", the value is a valid file path to an image.</value>
</data>
</root>
Copy link
Member

Choose a reason for hiding this comment

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

There's a good amount of "changes" here that actually don't exist. Please be sure to fix that.

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jan 13, 2020
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jan 14, 2020
@mkitzan
Copy link
Contributor Author

mkitzan commented Jan 14, 2020

@carlos-zamora, I removed the weird auto-formatting changes on the Resources.resw.

@miniksa
Copy link
Member

miniksa commented Jan 14, 2020

Nnnnn this crash also happens with the icons for profiles if they're not found too. Can we check that one too or somehow make this check more generic?

@mkitzan
Copy link
Contributor Author

mkitzan commented Jan 14, 2020

@miniksa, I originally didn't validate/correct icons because it appears that it no longer repros. However, might as well validate/correct invalid icon image paths (the check is painless). The latest commit performs the same checks to icons as background images, and displays this error message:
error

@mkitzan mkitzan changed the title Fix crash related to unparseable/invalid background image file path Fix crash related to unparseable/invalid media resource paths Jan 14, 2020
@miniksa
Copy link
Member

miniksa commented Jan 14, 2020

@miniksa Michael Niksa FTE, I originally didn't validate/correct icons because it appears that it no longer repros. However, might as well validate/correct invalid icon image paths (the check is painless). The latest commit performs the same checks to icons as background images, and displays this error message:
error

Whoa, ok. Something must have changed since a month or two ago when I got crashes for missing icons. Either way, thanks for covering it.

Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Copy link
Contributor

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

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

Thanks so much!

@DHowett-MSFT DHowett-MSFT dismissed carlos-zamora’s stale review January 17, 2020 01:45

It looks like your review comment has been addressed.

@DHowett-MSFT DHowett-MSFT merged commit 77dd51a into microsoft:master Jan 17, 2020
@mkitzan mkitzan deleted the validate-background-image branch January 17, 2020 02:58
DHowett-MSFT pushed a commit that referenced this pull request Jan 24, 2020
WT crashes when an unparseable/invalid `backgroundImage` or `icon`
resource path is provided in `profiles.json`. This PR averts the crash
by the validating and correcting 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` or `icon` resource path is detected, a
warning screen will be presented.

References #4002, which identified a consistent repro for the crash.

To validate the resource, 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.

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).

Closes #2329

(cherry picked from commit 77dd51a)
@ghost
Copy link

ghost commented Jan 27, 2020

🎉Windows Terminal Preview v0.8.10261.0 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented Feb 13, 2020

🎉Windows Terminal Preview v0.9.433.0 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows Terminal crashes when a profile's icon URL or background is unparseable/invalid
5 participants