[webkit-changes] [WebKit/WebKit] 612abb: [macOS] Crash when using opacity slider in color p...

Aditya Keerthi noreply at github.com
Wed Nov 15 12:49:57 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 612abb26e5a37b436b588e166327b8145cbbe9b2
      https://github.com/WebKit/WebKit/commit/612abb26e5a37b436b588e166327b8145cbbe9b2
  Author: Aditya Keerthi <akeerthi at apple.com>
  Date:   2023-11-15 (Wed, 15 Nov 2023)

  Changed paths:
    M Source/WTF/wtf/PlatformHave.h
    M Source/WebCore/html/ColorInputType.cpp
    M Source/WebKit/UIProcess/API/mac/WKWebViewPrivateForTestingMac.h
    M Source/WebKit/UIProcess/API/mac/WKWebViewTestingMac.mm
    M Source/WebKit/UIProcess/mac/WebColorPickerMac.mm
    M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
    A Tools/TestWebKitAPI/Tests/mac/ColorInputTests.mm

  Log Message:
  -----------
  [macOS] Crash when using opacity slider in color picker
https://bugs.webkit.org/show_bug.cgi?id=264690
rdar://118408313

Reviewed by Richard Robinson.

The color input type does not support alpha values. However, `NSColorPanel`
shows an opacity slider by default. Currently, when a color with opacity is
selected, it is simply forwarded to the Web Process, serialized for HTML, and
directly set as the string value on the input.

The current logic has two flaws:

1. It actually allows for the value of color inputs to deviate from the standard
   "#rrggbb", since the serialization of a value with alpha is "rgba(...)".

2. Eventually results in a crash as other logic (fairly) assumes that the value
   is empty, or is a valid color string of the "#rrggbb". Specifically, an
   empty optional dereference occurs, as the HTML color parsing fails.

To fix, sanitize the color value such that the alpha value is always forced to 1.
The value string itself is not sanitized to avoid unexpectedly forcing a black
color once a non-1 alpha value appears.

Additionally, on macOS 14, where it is now possible to hide the opacity slider,
adopt the `-[NSColorWell supportsAlpha]` API.

* Source/WTF/wtf/PlatformHave.h:
* Source/WebCore/html/ColorInputType.cpp:
(WebCore::ColorInputType::didChooseColor):

The final sanitization runs in the Web Process rather than the UI process to
support an eventual goal where color inputs can support alpha and other color
spaces.

* Source/WebKit/UIProcess/API/mac/WKWebViewPrivateForTestingMac.h:
* Source/WebKit/UIProcess/API/mac/WKWebViewTestingMac.mm:
(-[WKWebView _setSelectedColorForColorPicker:]):
* Source/WebKit/UIProcess/mac/WebColorPickerMac.mm:
(-[WKColorPopoverMac setAndShowPicker:withColor:suggestions:]):
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/mac/ColorInputTests.mm: Added.
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/270786@main




More information about the webkit-changes mailing list