fix(macos): Guard nil WKWebView title to prevent native SIGSEGV by ajpinedam · Pull Request #23642 · unoplatform/uno · GitHub
Skip to content

fix(macos): Guard nil WKWebView title to prevent native SIGSEGV#23642

Open
ajpinedam wants to merge 3 commits into
unoplatform:masterfrom
ajpinedam:dev/anpi/investigate.crash.macos26.x64
Open

fix(macos): Guard nil WKWebView title to prevent native SIGSEGV#23642
ajpinedam wants to merge 3 commits into
unoplatform:masterfrom
ajpinedam:dev/anpi/investigate.crash.macos26.x64

Conversation

@ajpinedam

@ajpinedam ajpinedam commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: #23641

PR Type:

🐞 Bugfix

What changed? 🚀

uno_webview_get_title (macOS Skia native WebView) called strdup(webview.title.UTF8String) directly. WKWebView.title is nullable; when it is nil, [nil UTF8String] returns NULL and strdup(NULL) dereferences null → SIGSEGV. This guards it:

NSString *title = webview.title ?: @"";
return strdup(title.UTF8String);

"" preserves the existing behavior: CoreWebView2.DocumentTitle already coalesces to "", _previousTitle seeds to "" (so no spurious DocumentTitleChanged), and it matches WinUI parity (a title-less page returns ""). Allocation/free ownership is unchanged (still a strdup buffer freed by the UTF-8 return marshaller).

Also adds a When_DocumentTitle_Before_Navigation runtime test asserting DocumentTitle returns "" (rather than crashing) on a fresh web view.

Scope / honesty note: this targets the intermittent macOS 26 / x64 SIGSEGV in the Given_WebView2.When_ExecuteScriptAsync* runtime tests (#23641). The crash could not be reproduced locally (~65 runs on a matching macOS 26.4.1 / x64 machine, incl. NSZombieEnabled and MallocScribble; instrumentation showed title was never nil across ~70 navigations). So this is a defensive nullability fix, not a confirmed root-cause fix — but WKWebView.title is nullable by API, so strdup(NULL) is a real latent crash worth closing regardless. Whether it resolves the CI crash will be shown by the macOS runtime-test leg; #23641 is left open until confirmed.

PR Checklist ✅

  • 🧪 Added a runtime test (When_DocumentTitle_Before_Navigation)
  • 📚 Docs — N/A (internal native fix, no public API change)
  • 🖼️ Validated PR Screenshots Compare Test Run results — N/A (no visual change)
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests

🤖 Generated with Claude Code

https://claude.ai/code/session_0178mJtoQEwreA2zrADWUgqP

Copilot AI review requested due to automatic review settings July 3, 2026 19:23
@github-actions github-actions Bot added platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform area/automation Categorizes an issue or PR as relevant to project automation labels Jul 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Defensive hardening for the macOS Skia native WebView title accessor to avoid a native crash when WKWebView.title is nil, plus a runtime test covering the “title before navigation” case.

Changes:

  • Guard WKWebView.title against nil in uno_webview_get_title before calling strdup.
  • Add a runtime test asserting CoreWebView2.DocumentTitle returns "" on a fresh WebView2 (no navigation yet).
  • Add a new SamplesApp manual test page for ContentDialog auto-focus / soft-keyboard behavior (appears unrelated to this PR’s stated scope).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/Uno.UI.Runtime.Skia.MacOS/UnoNativeMac/UnoNativeMac/UNOWebView.m Prevents strdup(NULL) by coalescing nullable WKWebView.title to an empty string.
src/Uno.UI.RuntimeTests/Tests/Microsoft_UI_Xaml_Controls/Given_WebView2.cs Adds regression coverage for reading DocumentTitle before any navigation.
src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml/FocusManager/ContentDialog_AutoFocusTextBox.xaml.cs Adds a new manual sample page (also contains a build-breaking unused using).
src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml/FocusManager/ContentDialog_AutoFocusTextBox.xaml XAML UI for the new manual sample page.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23642/wasm-skia-net9/index.html

Copilot AI review requested due to automatic review settings July 3, 2026 22:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23642/wasm-skia-net9/index.html

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 220694 has failed on Uno.UI - CI.

Copilot AI review requested due to automatic review settings July 4, 2026 05:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23642/wasm-skia-net9/index.html

ajpinedam and others added 3 commits July 4, 2026 18:38
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 4, 2026 22:41
@ajpinedam ajpinedam force-pushed the dev/anpi/investigate.crash.macos26.x64 branch from 7bb0e11 to ea15d2a Compare July 4, 2026 22:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@unodevops

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants