Fix use-after-free crash in BrowserView.get_instance on macOS#1797
Open
smparkes wants to merge 2 commits intor0x0r:masterfrom
Open
Fix use-after-free crash in BrowserView.get_instance on macOS#1797smparkes wants to merge 2 commits intor0x0r:masterfrom
smparkes wants to merge 2 commits intor0x0r:masterfrom
Conversation
a059824 to
b72b9ce
Compare
Author
|
Hmmm ... not sure about Comprehensive CI / macOS (pull_request)Cancelled after 20m Timeout? |
- Replace OpenFolderDialog's FileDialogNative internals with FolderBrowserDialog
(FileDialogNative+IFileDialog doesn't exist in .NET 8)
- Update WebView2 DLLs from 1.0.2957 (.NET Framework) to 1.0.3240 (netcoreapp3.0)
(old DLLs reference System.Windows.Forms.ContextMenu, removed in .NET 6+)
- Skip .NET Framework registry check in _is_chromium() when using coreclr
- Add explicit clr.AddReference('Microsoft.Win32.SystemEvents') for coreclr
(not auto-loaded like on netfx)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
On macOS ARM64, the app crashes with EXC_BREAKPOINT (SIGTRAP, pointer authentication trap) in object_getClass when a deferred Cocoa callback (performSelectorOnMainThread) fires after a window has been destroyed. Root cause: get_instance iterates BrowserView.instances comparing each instance's .window attribute against a target NSWindow. When a window has been destroyed (windowWillClose_ releases the window), the .window attribute points to freed memory. Comparing it triggers object_getClass on the freed pointer, which fails the ARM64 pointer authentication check and kills the process. The original code had two bugs: 1. Used bare getattr(i, attr) — crashes if the attribute value is a freed Cocoa object whose __eq__ triggers object_getClass 2. Caught only AttributeError and used break — stops searching on any missing attribute, missing valid instances later in the dict Fix get_instance to: - Use getattr(i, attr, None) with a None check to skip freed/cleared attributes without comparing them - Catch all exceptions (not just AttributeError) during comparison - Continue iterating instead of breaking, so later valid instances are still found Also fix windowWillClose_ to: - Clear the window delegate (setDelegate_(None)) before releasing, preventing further delegate callbacks on the freed window - Guard against missing instance (if not i: return) - Guard webview access (if i.webview:) before cleanup And fix windowShouldClose_ to return YES if instance not found. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
b72b9ce to
a07f8a7
Compare
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.
On macOS ARM64, the app crashes with EXC_BREAKPOINT (SIGTRAP, pointer authentication trap) in object_getClass when a deferred Cocoa callback (performSelectorOnMainThread) fires after a window has been destroyed.
Root cause: get_instance iterates BrowserView.instances comparing each instance's .window attribute against a target NSWindow. When a window has been destroyed (windowWillClose_ releases the window), the .window attribute points to freed memory. Comparing it triggers object_getClass on the freed pointer, which fails the ARM64 pointer authentication check and kills the process.
The original code had two bugs:
Fix get_instance to:
Also fix windowWillClose_ to:
And fix windowShouldClose_ to return YES if instance not found.