Repository navigation
[Android] Fix WebView SIGSEGV crash in GLFunctorDrawable on ScrollView overscroll (#38080) #38181
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
Closed
ne0rrmatrix
wants to merge
7
commits into
dotnet:main
from
ne0rrmatrix:fix/issue38080-android-webview-overscroll-crash
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1c8ca42
[Android] Fix WebView SIGSEGV crash in GLFunctorDrawable on ScrollVie…
ne0rrmatrix 55f3fde
Fix scroll direction in Issue38080 test cases
ne0rrmatrix 1348a1f
Guard Issue38080 test against silent no-op scroll on missing ScrollView
ne0rrmatrix 0b777da
Assert Issue38080 test reaches both overscroll extremes
ne0rrmatrix 69784ab
[Android] Preserve WebView bounds with native child clipping
kubaflo d2d3fb0
Handle nullable WebView HTML probe text explicitly
kubaflo 9c58efd
Add using directives for System and Linq in tests
ne0rrmatrix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
178 changes: 178 additions & 0 deletions
178
src/Controls/tests/TestCases.HostApp/Issues/Issue38080.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 38080, "Android SIGSEGV crash in GLFunctorDrawable when a ScrollView with an off-screen WebView is overscrolled", PlatformAffected.Android)] | ||
| public class Issue38080 : NavigationPage | ||
| { | ||
| public Issue38080() : base(new Issue38080HomePage()) { } | ||
|
|
||
| class Issue38080HomePage : ContentPage | ||
| { | ||
| public Issue38080HomePage() | ||
| { | ||
| Content = new VerticalStackLayout | ||
| { | ||
| VerticalOptions = LayoutOptions.Center, | ||
| Children = | ||
| { | ||
| new Button | ||
| { | ||
| AutomationId = "Issue38080NavigateButton", | ||
| Text = "Open repro page", | ||
| Command = new Command(async () => await Navigation.PushAsync(new Issue38080ReproPage())) | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| // Reproduces #38080: a single fixed-size WebView placed mid-list in a ScrollView is off-screen | ||
| // at both scroll extremes. Flinging to either extreme (or back-navigating) previously SIGSEGV'd | ||
| // the RenderThread in GLFunctorDrawable because the WebView carried a non-null ClipBounds that | ||
| // routed its off-screen compositing through the AOSP hwui GL-functor path. | ||
| class Issue38080ReproPage : ContentPage | ||
| { | ||
| const int FillerRows = 50; | ||
| const int MaxDiagnosticRefreshAttempts = 50; | ||
|
|
||
| public Issue38080ReproPage() | ||
| { | ||
| var stack = new VerticalStackLayout | ||
| { | ||
| Padding = new Thickness(12), | ||
| Spacing = 12 | ||
| }; | ||
|
|
||
| stack.Children.Add(new Label | ||
| { | ||
| AutomationId = "Issue38080Ready", | ||
| Text = "Page loaded — no crash" | ||
| }); | ||
|
|
||
| var clipBoundsStatus = new Label | ||
| { | ||
| AutomationId = "Issue38080ClipBoundsStatus", | ||
| Text = "ClipBounds=pending" | ||
| }; | ||
| stack.Children.Add(clipBoundsStatus); | ||
|
|
||
| var webViewLoadStatus = new Label | ||
| { | ||
| AutomationId = "Issue38080WebViewLoadStatus", | ||
| Text = "WebView load pending" | ||
| }; | ||
|
|
||
| // The first/last rows are sentinels the UITest asserts on to prove the scroll | ||
| // actually reached the top/bottom extreme. | ||
| AddFiller(stack, FillerRows, sentinelRow: 1, sentinelId: "Issue38080TopSentinel"); | ||
|
|
||
| stack.Children.Add(new Label | ||
| { | ||
| AutomationId = "Issue38080WebViewTopMarker", | ||
| Text = "Issue38080 WebView starts below" | ||
| }); | ||
|
|
||
| // Single fixed-size WebView mid-list, so it is off-screen at both extremes. | ||
| var webView = new WebView | ||
| { | ||
| AutomationId = "Issue38080WebView", | ||
| HeightRequest = 220, | ||
| Source = new HtmlWebViewSource | ||
| { | ||
| Html = "<html><body style='background:#d6e4ff; margin:0; padding:24px'><h3 id='Issue38080HtmlProbe'>Issue38080 WebView HTML loaded</h3></body></html>" | ||
| } | ||
| }; | ||
| RegisterWebViewDiagnostics(webView, clipBoundsStatus, webViewLoadStatus); | ||
| stack.Children.Add(webView); | ||
| stack.Children.Add(webViewLoadStatus); | ||
|
|
||
| AddFiller(stack, FillerRows, sentinelRow: FillerRows, sentinelId: "Issue38080BottomSentinel"); | ||
|
|
||
| Content = new ScrollView | ||
| { | ||
| AutomationId = "Issue38080ScrollView", | ||
| Content = stack | ||
| }; | ||
| } | ||
|
|
||
| static void AddFiller(VerticalStackLayout stack, int rows, int sentinelRow, string sentinelId) | ||
| { | ||
| for (int i = 1; i <= rows; i++) | ||
| { | ||
| stack.Children.Add(new Label | ||
| { | ||
| AutomationId = i == sentinelRow ? sentinelId : null, | ||
| Text = $"Filler row {i}", | ||
| FontSize = 20 | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| static void RegisterWebViewDiagnostics(WebView webView, Label diagnosticsLabel, Label loadStatusLabel) | ||
| { | ||
| webView.Navigated += async (_, args) => | ||
| { | ||
| if (args.Result != WebNavigationResult.Success) | ||
| { | ||
| loadStatusLabel.Text = $"WebView load result: {args.Result}"; | ||
| return; | ||
| } | ||
|
|
||
| var htmlProbe = await webView.EvaluateJavaScriptAsync("document.getElementById('Issue38080HtmlProbe').textContent"); | ||
| loadStatusLabel.Text = $"WebView load result: {args.Result}; HtmlProbe={htmlProbe}"; | ||
| }; | ||
|
|
||
| #if ANDROID | ||
| webView.HandlerChanged += (_, _) => UpdateClipBoundsDiagnostics(webView, diagnosticsLabel, attempt: 0); | ||
| webView.Loaded += (_, _) => UpdateClipBoundsDiagnostics(webView, diagnosticsLabel, attempt: 0); | ||
| webView.SizeChanged += (_, _) => UpdateClipBoundsDiagnostics(webView, diagnosticsLabel, attempt: 0); | ||
| #endif | ||
| } | ||
|
|
||
| #if ANDROID | ||
| static void UpdateClipBoundsDiagnostics(WebView webView, Label diagnosticsLabel, int attempt) | ||
| { | ||
| var nativeWebView = webView.Handler?.PlatformView as Android.Webkit.WebView; | ||
| var diagnosticsReady = false; | ||
|
|
||
| if (nativeWebView is null) | ||
| { | ||
| diagnosticsLabel.Text = "ClipBounds=pending; NativeWebView=null"; | ||
| } | ||
| else | ||
| { | ||
| using var clipBounds = nativeWebView.ClipBounds; | ||
| var clipBoundsText = clipBounds is null | ||
| ? "null" | ||
| : $"{clipBounds.Left},{clipBounds.Top},{clipBounds.Right},{clipBounds.Bottom}"; | ||
| var nativeParent = nativeWebView.Parent; | ||
| var parentViewGroup = nativeParent as Android.Views.ViewGroup; | ||
| var parentClipChildren = parentViewGroup is null | ||
| ? "null" | ||
| : parentViewGroup.ClipChildren.ToString(); | ||
| var parentType = nativeParent?.GetType().Name ?? "null"; | ||
| var isAttachedToWindow = nativeWebView.IsAttachedToWindow; | ||
| var isHardwareAccelerated = nativeWebView.IsHardwareAccelerated; | ||
|
|
||
| diagnosticsReady = | ||
| nativeWebView.Width > 0 && | ||
| nativeWebView.Height > 0 && | ||
| isAttachedToWindow && | ||
| isHardwareAccelerated; | ||
|
|
||
| diagnosticsLabel.Text = | ||
| $"ClipBounds={clipBoundsText}; " + | ||
| $"Size={nativeWebView.Width}x{nativeWebView.Height}; " + | ||
| $"IsAttachedToWindow={isAttachedToWindow}; " + | ||
| $"HardwareAccelerated={isHardwareAccelerated}; " + | ||
| $"Parent={parentType}; " + | ||
| $"ParentClipChildren={parentClipChildren}"; | ||
| } | ||
|
|
||
| if (!diagnosticsReady && attempt < MaxDiagnosticRefreshAttempts) | ||
| webView.Dispatcher.DispatchDelayed(TimeSpan.FromMilliseconds(100), () => UpdateClipBoundsDiagnostics(webView, diagnosticsLabel, attempt + 1)); | ||
| else if (!diagnosticsReady) | ||
| diagnosticsLabel.Text += "; DiagnosticsTimeout=True"; | ||
| } | ||
| #endif | ||
| } | ||
| } |
140 changes: 140 additions & 0 deletions
140
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue38080.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // Crash is Android-specific: RenderThread GL functor SIGSEGVs when a non-null ClipBounds | ||
| // routes an off-screen WebView's compositing through GLFunctorDrawable on overscroll. | ||
| #if ANDROID | ||
| using System; | ||
| using System.Linq; | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue38080 : _IssuesUITest | ||
| { | ||
| public Issue38080(TestDevice device) : base(device) { } | ||
|
|
||
| public override string Issue => "Android SIGSEGV crash in GLFunctorDrawable when a ScrollView with an off-screen WebView is overscrolled"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.WebView)] | ||
| public void OffScreenWebViewInScrollViewShouldNotCrashOnOverscroll() | ||
| { | ||
| App.WaitForElement("Issue38080NavigateButton"); | ||
| App.Tap("Issue38080NavigateButton"); | ||
| App.WaitForElement("Issue38080Ready"); | ||
|
|
||
| // ScrollUp/ScrollDown silently no-op when the element lookup returns null, which would | ||
| // turn this regression test into a false positive. Wait so a failed lookup fails the test. | ||
| App.WaitForElement("Issue38080ScrollView"); | ||
| AssertFixedSizeWebViewIsMeasuredAndHardwareAccelerated(); | ||
| ScrollToAndAssertWebViewRendered(); | ||
|
|
||
| // Overscroll at the top extreme: the WebView is off-screen below the fold and the | ||
| // ScrollView overscrolls past its top edge. | ||
| ScrollToExtremeAndAssert("Issue38080TopSentinel", "top", scrollDown: false, swipePercentage: 0.9); | ||
|
|
||
| // Scroll/overscroll at the bottom extreme: the WebView is off-screen above the fold and the | ||
| // ScrollView overscrolls past its bottom edge. | ||
| // Use a mid-viewport gesture for the downward pass: once the WebView is visible near the | ||
| // bottom of the viewport, a bottom-origin fling can be consumed by the WebView itself instead | ||
| // of the parent ScrollView, leaving the test stuck at the midpoint. | ||
| ScrollToExtremeAndAssert("Issue38080BottomSentinel", "bottom", scrollDown: true, swipePercentage: 0.45); | ||
|
|
||
| // The WebView is now off-screen at the bottom; back navigation also reproduced the | ||
| // RenderThread crash while compositing. Assert we returned to the home page alive. | ||
| App.Back(); | ||
| App.WaitForElement("Issue38080NavigateButton"); | ||
| } | ||
|
|
||
| void ScrollToExtremeAndAssert(string automationId, string extreme, bool scrollDown, double swipePercentage) | ||
| { | ||
| for (int i = 0; i < 60 && !TrySentinelDisplayed(automationId); i++) | ||
| ScrollOnce(scrollDown, swipePercentage); | ||
|
|
||
| AssertSentinelDisplayed(automationId, extreme); | ||
|
|
||
| // Exercise actual overscroll at the edge after proving we reached it. | ||
| for (int overscroll = 0; overscroll < 5; overscroll++) | ||
| ScrollOnce(scrollDown, swipePercentage); | ||
|
|
||
| AssertSentinelDisplayed(automationId, extreme); | ||
| } | ||
|
|
||
| void ScrollOnce(bool scrollDown, double swipePercentage) | ||
| { | ||
| if (scrollDown) | ||
| App.ScrollDown("Issue38080ScrollView", ScrollStrategy.Gesture, swipePercentage, 100); | ||
| else | ||
| App.ScrollUp("Issue38080ScrollView", ScrollStrategy.Gesture, swipePercentage, 100); | ||
| } | ||
|
|
||
| bool TrySentinelDisplayed(string automationId) => | ||
| App.FindElements(automationId).Any(element => element.IsDisplayed()); | ||
|
|
||
| // Displayed is a viewport check, not a view-hierarchy presence check: it proves the sentinel | ||
| // row is actually on screen at the extreme, so ignored/flaky scroll gestures fail the test | ||
| // instead of letting it pass as a false positive. | ||
| void AssertSentinelDisplayed(string automationId, string extreme) | ||
| { | ||
| App.RetryAssert(() => | ||
| { | ||
| var sentinel = App.WaitForElement(automationId, timeout: TimeSpan.FromSeconds(5)); | ||
| Assert.That(sentinel.IsDisplayed(), Is.True, | ||
| $"The {extreme} extreme was not reached: {automationId} is not displayed after scrolling"); | ||
| }, timeout: TimeSpan.FromSeconds(30)); | ||
| } | ||
|
|
||
| void AssertFixedSizeWebViewIsMeasuredAndHardwareAccelerated() | ||
| { | ||
| App.RetryAssert(() => | ||
| { | ||
| var statusText = App.WaitForElement("Issue38080ClipBoundsStatus", timeout: TimeSpan.FromSeconds(5)).GetText(); | ||
| Assert.That(statusText, Does.Match(@"Size=[1-9]\d*x[1-9]\d*"), | ||
| $"The diagnostic assertion should only pass after the native WebView has non-zero dimensions. Actual diagnostics: {statusText}"); | ||
| Assert.That(statusText, Does.Contain("IsAttachedToWindow=True"), | ||
| $"The diagnostic assertion should only pass after the native WebView is attached. Actual diagnostics: {statusText}"); | ||
| Assert.That(statusText, Does.Contain("HardwareAccelerated=True"), | ||
| $"This regression must exercise Android hardware-accelerated WebView rendering. Actual diagnostics: {statusText}"); | ||
| Assert.That(statusText, Does.Contain("ParentClipChildren=True"), | ||
| $"The native WebView should be clipped by its Android parent wrapper. Actual diagnostics: {statusText}"); | ||
| Assert.That(statusText, Does.Not.Contain("DiagnosticsTimeout=True"), | ||
| $"The native WebView diagnostics timed out before reaching a ready attached/hardware-accelerated state. Actual diagnostics: {statusText}"); | ||
| }, timeout: TimeSpan.FromSeconds(30)); | ||
| } | ||
|
|
||
| void ScrollToAndAssertWebViewRendered() | ||
| { | ||
| for (int i = 0; i < 20; i++) | ||
| { | ||
| if (IsWebViewRenderedAndDisplayed()) | ||
| return; | ||
|
|
||
| App.ScrollDown("Issue38080ScrollView", ScrollStrategy.Gesture, 0.25, 100); | ||
| } | ||
|
|
||
| AssertWebViewRenderedAndDisplayed(); | ||
| } | ||
|
|
||
| bool IsWebViewRenderedAndDisplayed() | ||
| { | ||
| var topMarker = App.FindElements("Issue38080WebViewTopMarker").FirstOrDefault(); | ||
| var loadStatus = App.FindElements("Issue38080WebViewLoadStatus").FirstOrDefault(); | ||
| return topMarker?.IsDisplayed() == true && | ||
| loadStatus?.IsDisplayed() == true && | ||
| loadStatus.GetText()?.Contains("HtmlProbe=Issue38080 WebView HTML loaded", StringComparison.Ordinal) == true; | ||
| } | ||
|
|
||
| void AssertWebViewRenderedAndDisplayed() | ||
| { | ||
| var topMarker = App.WaitForElement("Issue38080WebViewTopMarker", timeout: TimeSpan.FromSeconds(1)); | ||
| Assert.That(topMarker.IsDisplayed(), Is.True, | ||
| "The marker immediately above the WebView must be visible before overscroll."); | ||
|
|
||
| var loadStatus = App.WaitForElement("Issue38080WebViewLoadStatus", timeout: TimeSpan.FromSeconds(1)); | ||
| Assert.That(loadStatus.IsDisplayed(), Is.True, | ||
| "The WebView load status label immediately below the WebView should be visible with the midpoint check."); | ||
| Assert.That(loadStatus.GetText(), Does.Contain("HtmlProbe=Issue38080 WebView HTML loaded"), | ||
| "The WebView HTML must finish loading before the off-screen overscroll checks run."); | ||
| } | ||
| } | ||
| #endif | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.