Repository: microsoft/terminal (language: cpp)

Issue:
Canary [regression] Trap when trying to use background image alignment that is not centered
### Windows Terminal version

1.23.10282.0

### Windows build number

10.0.19045.3448

### Other Software

_No response_

### Steps to reproduce

1) Set use background image in default profile
2) Try use any alignment background image that is not centered
for example in settings.json:
            "backgroundImageAlignment": "bottomRight",

after we got exception...

100% reproduced.

Windows create crashdump.


### Expected Behavior

under Canary build:
..
terminal-1.23.10151.0 - latest good


### Actual Behavior

terminal-1.23.10221.0 - with trouble
terminal-1.23.10271.0 - with trouble
terminal-1.23.10282.0 - with trouble



Discussion / hints:
ExceptionAddress: 00007ff9ddf0fc29 (Microsoft_Terminal_Settings_Editor!winrt::impl::consume_Windows_ApplicationModel_Resources_Core_IResourceCandidate<winrt::Windows::ApplicationModel::Resources::Core::IResourceCandidate>::ValueAsString+0x000000000000002a)
   ExceptionCode: c0000005 (Access violation)

STACK_TEXT: 
Microsoft_Terminal_Settings_Editor!GetLibraryResourceString+0x159
Microsoft_Terminal_Settings_Editor!winrt::Microsoft::Terminal::Settings::Editor::implementation::AppearanceViewModel::BackgroundImageAlignmentCurrentValue+0x496
Microsoft_Terminal_Settings_Editor!winrt::impl::produce<winrt::Microsoft::Terminal::Settings::Editor::implementation::AppearanceViewModel,winrt::Microsoft::Terminal::Settings::Editor::IAppearanceViewModel>::get_BackgroundImageAlignmentCurrentValue+0x2a

@carlos-zamora this is in the new SUI a11y previews

Fix patch:
diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.cpp b/src/cascadia/TerminalSettingsEditor/Appearances.cpp
index 38904487e4b..536217cc6ae 100644
--- a/src/cascadia/TerminalSettingsEditor/Appearances.cpp
+++ b/src/cascadia/TerminalSettingsEditor/Appearances.cpp
@@ -927,7 +927,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
         else
         {
             // Append vertical alignment to the resource key
-            switch (alignment & static_cast<ConvergedAlignment>(0x0F))
+            switch (alignment & static_cast<ConvergedAlignment>(0xF0))
             {
             case ConvergedAlignment::Vertical_Bottom:
                 alignmentResourceKey = alignmentResourceKey + L"Bottom";
@@ -938,7 +938,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
             }
 
             // Append horizontal alignment to the resource key
-            switch (alignment & static_cast<ConvergedAlignment>(0xF0))
+            switch (alignment & static_cast<ConvergedAlignment>(0x0F))
             {
             case ConvergedAlignment::Horizontal_Left:
                 alignmentResourceKey = alignmentResourceKey + L"Left";


Test patch: