TextStore: initialize callback state before RegisterTextStore#11457
Open
etvorun wants to merge 1 commit intodotnet:mainfrom
Open
TextStore: initialize callback state before RegisterTextStore#11457etvorun wants to merge 1 commit intodotnet:mainfrom
etvorun wants to merge 1 commit intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical reentrancy bug in the WPF TextStore's TSF (Text Services Framework) integration where third-party IMEs can trigger callbacks during RegisterTextStore, before all initialization state is ready. The fix reorders initialization in OnAttach() to ensure callback-facing state is fully initialized before TSF registration.
Changes:
- Initialize
_textservicespropertybeforeRegisterTextStoreto prevent null dereference in TSF callbacks - Subscribe to
TextContainer.ChangebeforeRegisterTextStoreto keep_netCharCountsynchronized during registration-time edits - Add detailed comments explaining the reentrancy scenario and specific IME that exhibits this behavior
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes a TextStore attach-time reentrancy window where TSF callbacks can arrive during
TextStore.OnAttach()before attach-time state is fully safe.What changed
In
TextStore.OnAttach():_textservicesproperty) beforeRegisterTextStore.TextContainer.ChangebeforeRegisterTextStoreso registration-time edits update_netCharCountimmediately.Why
RegisterTextStorecan synchronously re-enter WPF with third-party IMEs/TIPs. If attach-time edits happen before text-change tracking is hooked,_netCharCountcan drift fromTextContainer.IMECharCount, causing later consistency failures.Validation
_netCharCountremains synchronized in this path.Fixes #11456
Microsoft Reviewers: Open in CodeFlow