Skip to content

Commit bdc9ba2

Browse files
committed
jsc_fuz/wktr: null ptr deref in WebCore::GraphicsLayerAsyncContentsDisplayDelegateCocoa::tryCopyToLayer(WebCore::ImageBuffer&)
https://bugs.webkit.org/show_bug.cgi?id=262640 <rdar://115497296> Reviewed by Kimmo Kinnunen. This adds support for setDelegatedContents on a PlatformCALayerRemote having a generic ImageBufferBackendHandle (which includes shared memory), instead of only MachSendRight. Adds an explicit copy constructor to SharedMemoryHandle, UnixFileDescriptor and CGDisplayList to match MachSendRight and make this possible. Also switches Protection::ReadWrite to Protection::ReadOnly for the RemoteLayerBackingStore callers, since we were already using this for tryCopyToLayer, and we need the ::map() call in the UI process to not try ask for extra permissions. * Source/WTF/wtf/unix/UnixFileDescriptor.h: (WTF::UnixFileDescriptor::UnixFileDescriptor): * Source/WebKit/Platform/SharedMemory.h: * Source/WebKit/Shared/RemoteLayerTree/CGDisplayList.h: * Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h: * Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm: (WebKit::RemoteLayerBackingStore::encode const): (WebKit::RemoteLayerBackingStore::setDelegatedContents): (WebKit::RemoteLayerBackingStoreProperties::layerContentsBufferFromBackendHandle): * Source/WebKit/Shared/ShareableBitmap.h: * Source/WebKit/WebProcess/WebPage/RemoteLayerTree/GraphicsLayerCARemote.mm: * Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.h: * Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.mm: (WebKit::PlatformCALayerRemote::setDelegatedContents): (WebKit::PlatformCALayerRemote::setRemoteDelegatedContents): Originally-landed-as: 267815.262@safari-7617-branch (8ac1946). rdar://119570861 Canonical link: https://commits.webkit.org/272365@main
1 parent 6fb4594 commit bdc9ba2

File tree

15 files changed

+92
-16
lines changed

15 files changed

+92
-16
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<canvas id="onscreen" width="100" height="10""></canvas>
5+
<script>
6+
const canvas = document.getElementById('onscreen');
7+
8+
const context = canvas.getContext('2d');
9+
10+
const square = new Path2D();
11+
square.rect(0, 0, 100, 10);
12+
context.fillStyle = 'green';
13+
context.fill(square);
14+
15+
</script>
16+
</body>
17+
</html>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="fuzzy" content="maxDifference=0-64; totalPixels=0-10" />
5+
</head>
6+
<body style="overflow:hidden">
7+
<canvas id="offscreen"></canvas>
8+
<script>
9+
const canvas = document.getElementById('offscreen');
10+
11+
const offscreenCanvas = canvas.transferControlToOffscreen();
12+
offscreenCanvas.width = 200000;
13+
offscreenCanvas.height = 10;
14+
15+
const offscreenContext = offscreenCanvas.getContext('2d');
16+
17+
if (window.testRunner)
18+
testRunner.waitUntilDone();
19+
20+
requestAnimationFrame(function() {
21+
const square = new Path2D();
22+
square.rect(0, 0, 100, 10);
23+
offscreenContext.fillStyle = 'green';
24+
offscreenContext.fill(square);
25+
offscreenContext.commit();
26+
27+
requestAnimationFrame(function() {
28+
if (window.testRunner)
29+
testRunner.notifyDone();
30+
});
31+
});
32+
</script>
33+
</body>
34+
</html>

LayoutTests/platform/glib/TestExpectations

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,6 +3757,8 @@ webkit.org/b/266636 fast/multicol/last-set-crash.html [ Skip ]
37573757

37583758
webkit.org/b/266708 imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/loading-the-media-resource/resource-selection-currentSrc.html [ Pass Crash ]
37593759

3760+
webkit.org/b/266719 fast/canvas/offscreen-giant.html [ ImageOnlyFailure ]
3761+
37603762
# End: Common failures between GTK and WPE.
37613763

37623764
#////////////////////////////////////////////////////////////////////////////////////////

LayoutTests/platform/mac-monterey/TestExpectations

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77

88
# Failing after OS migration rdar://112624778 (Migrate macOS Sonoma test expectations to OpenSource, add expectation files to Down-Levels (259373))
99
http/tests/appcache/fail-on-update-2.html [ DumpJSConsoleLogInStdErr Timeout Failure ]
10+
11+
fast/canvas/offscreen-giant.html [ ImageOnlyFailure ]

Source/WTF/wtf/unix/UnixFileDescriptor.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
namespace WTF {
3535

3636
class UnixFileDescriptor {
37-
WTF_MAKE_NONCOPYABLE(UnixFileDescriptor);
3837
public:
3938
UnixFileDescriptor() = default;
4039

@@ -55,6 +54,12 @@ class UnixFileDescriptor {
5554
m_value = o.release();
5655
}
5756

57+
explicit UnixFileDescriptor(const UnixFileDescriptor& o)
58+
{
59+
if (o.m_value >= 0)
60+
m_value = dupCloseOnExec(o.m_value);
61+
}
62+
5863
UnixFileDescriptor& operator=(UnixFileDescriptor&& o)
5964
{
6065
if (&o == this)

Source/WebCore/platform/graphics/ca/cocoa/GraphicsLayerAsyncContentsDisplayDelegateCocoa.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
bool GraphicsLayerAsyncContentsDisplayDelegateCocoa::tryCopyToLayer(ImageBuffer& image)
4444
{
4545
m_image = ImageBuffer::sinkIntoNativeImage(image.clone());
46+
if (!m_image)
47+
return false;
4648

4749
[CATransaction begin];
4850
[CATransaction setDisableActions:YES];

Source/WebCore/platform/graphics/cocoa/DynamicContentScalingDisplayList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
namespace WebCore {
3434

3535
class DynamicContentScalingDisplayList {
36-
WTF_MAKE_NONCOPYABLE(DynamicContentScalingDisplayList);
3736
public:
3837
DynamicContentScalingDisplayList(Ref<WebCore::SharedBuffer> displayList, Vector<MachSendRight>&& surfaces)
3938
: m_displayList(WTFMove(displayList))
4039
, m_surfaces(WTFMove(surfaces))
4140
{
4241
}
42+
explicit CGDisplayList(const CGDisplayList&) = default;
4343

4444
DynamicContentScalingDisplayList(DynamicContentScalingDisplayList&&) = default;
4545
DynamicContentScalingDisplayList& operator=(DynamicContentScalingDisplayList&&) = default;

Source/WebKit/Platform/SharedMemory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ namespace WebKit {
6060
enum class MemoryLedger { None, Default, Network, Media, Graphics, Neural };
6161

6262
class SharedMemoryHandle {
63-
WTF_MAKE_NONCOPYABLE(SharedMemoryHandle);
6463
public:
6564
using Type =
6665
#if USE(UNIX_DOMAIN_SOCKETS)
@@ -72,6 +71,7 @@ class SharedMemoryHandle {
7271
#endif
7372

7473
SharedMemoryHandle(SharedMemoryHandle&&) = default;
74+
explicit SharedMemoryHandle(const SharedMemoryHandle&) = default;
7575
SharedMemoryHandle(SharedMemoryHandle::Type&&, size_t);
7676

7777
SharedMemoryHandle& operator=(SharedMemoryHandle&&) = default;

Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class RemoteLayerBackingStoreCollection;
5454
class RemoteLayerTreeNode;
5555
class RemoteLayerTreeHost;
5656
enum class SwapBuffersDisplayRequirement : uint8_t;
57+
struct PlatformCALayerRemoteDelegatedContents;
5758

5859
enum class BackingStoreNeedsDisplayReason : uint8_t {
5960
None,
@@ -102,7 +103,7 @@ class RemoteLayerBackingStore : public CanMakeWeakPtr<RemoteLayerBackingStore> {
102103
void setNeedsDisplay(const WebCore::IntRect);
103104
void setNeedsDisplay();
104105

105-
void setDelegatedContents(const WebCore::PlatformCALayerDelegatedContents&);
106+
void setDelegatedContents(const PlatformCALayerRemoteDelegatedContents&);
106107

107108
// Returns true if we need to encode the buffer.
108109
bool layerWillBeDisplayed();
@@ -178,7 +179,7 @@ class RemoteLayerBackingStore : public CanMakeWeakPtr<RemoteLayerBackingStore> {
178179

179180
// FIXME: This should be removed and m_bufferHandle should be used to ref the buffer once ShareableBitmap::Handle
180181
// can be encoded multiple times. http://webkit.org/b/234169
181-
std::optional<MachSendRight> m_contentsBufferHandle;
182+
std::optional<ImageBufferBackendHandle> m_contentsBufferHandle;
182183
std::optional<WebCore::RenderingResourceIdentifier> m_contentsRenderingResourceIdentifier;
183184

184185
Vector<std::unique_ptr<WebCore::ThreadSafeImageBufferFlusher>> m_frontBufferFlushers;

Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static bool hasValue(const ImageBufferBackendHandle& backendHandle)
161161
std::optional<ImageBufferBackendHandle> handle;
162162
if (m_contentsBufferHandle) {
163163
ASSERT(m_parameters.type == Type::IOSurface);
164-
handle = MachSendRight { *m_contentsBufferHandle };
164+
handle = ImageBufferBackendHandle { *m_contentsBufferHandle };
165165
} else
166166
handle = frontBufferHandle();
167167

@@ -311,9 +311,9 @@ static bool hasValue(const ImageBufferBackendHandle& backendHandle)
311311
return !m_parameters.isOpaque && !m_layer->owner()->platformCALayerShouldPaintUsingCompositeCopy();
312312
}
313313

314-
void RemoteLayerBackingStore::setDelegatedContents(const WebCore::PlatformCALayerDelegatedContents& contents)
314+
void RemoteLayerBackingStore::setDelegatedContents(const PlatformCALayerRemoteDelegatedContents& contents)
315315
{
316-
m_contentsBufferHandle = MachSendRight { contents.surface };
316+
m_contentsBufferHandle = ImageBufferBackendHandle { contents.surface };
317317
if (contents.finishedFence)
318318
m_frontBufferFlushers.append(DelegatedContentsFenceFlusher::create(Ref { *contents.finishedFence }));
319319
if (contents.surfaceIdentifier)
@@ -478,7 +478,7 @@ static bool hasValue(const ImageBufferBackendHandle& backendHandle)
478478
RetainPtr<id> contents;
479479
WTF::switchOn(backendHandle,
480480
[&] (ShareableBitmap::Handle& handle) {
481-
if (auto bitmap = ShareableBitmap::create(WTFMove(handle)))
481+
if (auto bitmap = ShareableBitmap::create(WTFMove(handle), SharedMemory::Protection::ReadOnly))
482482
contents = bridge_id_cast(bitmap->makeCGImageCopy());
483483
},
484484
[&] (MachSendRight& machSendRight) {

0 commit comments

Comments
 (0)