[Cocoa] Calling -regularFileContents on a directory NSFileWrapper crashes the web content process#63020
Conversation
Collaborator
|
EWS run on current version of this PR (hash 704d7a1) Details
|
rniwa
approved these changes
Apr 18, 2026
…shes the web content process https://bugs.webkit.org/show_bug.cgi?id=312594 rdar://174642216 Reviewed by Ryosuke Niwa. When copying content containing an <img> element whose resolved URL points to a directory (e.g. srcset="."), WebKit can end up with a directory-backed NSFileWrapper. Calling -regularFileContents on such a wrapper raises an NSInvalidArgumentException. Because the exception unwinds through C++ stack frames in HTMLConverter and AttributedString, it is not caught and terminates the web content process. Fix by guarding both -regularFileContents call sites with -isRegularFile before extracting attachment data. The preferredFilename and other metadata are still read regardless of file type. Test: Tools/TestWebKitAPI/Tests/WebKit/WKWebView/CopyRTF.mm * Source/WebCore/editing/cocoa/AttributedString.mm: (WebCore::extractValue): * Source/WebCore/editing/cocoa/NodeHTMLConverter.mm: (HTMLConverter::_addAttachmentForElement): * Tools/TestWebKitAPI/Tests/WebKit/WKWebView/CopyRTF.mm: (TEST(CopyRTF, DoesNotCrashWithDirectoryFileWrapperFromImageSrcset)): Canonical link: https://commits.webkit.org/311610@main
704d7a1 to
dad1793
Compare
Collaborator
|
Committed 311610@main (dad1793): https://commits.webkit.org/311610@main Reviewed commits have been landed. Closing PR #63020 and removing active labels. |
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.
dad1793
704d7a1