From e2934b9029d0fb8381f11a719a8c33e7df5b18f8 Mon Sep 17 00:00:00 2001 From: Said Abou-Hallawa Date: Sat, 4 Nov 2023 06:43:49 -0700 Subject: [PATCH] [GPU Process] Ensure that only supported image decoders run in the WebProcess https://bugs.webkit.org/show_bug.cgi?id=256852 rdar://109414332 Reviewed by Brent Fulgham. Ensure that ImageIO is allowed to decode only the (default + additional) supported image types even outside WebKit rendering code path for example displaying a bitmap image in a PDF document. This work will be done for WK2 only. WK1 allows setting the prefrences only after creating the WebView. And we use the prefrences to set the additional supported image types. So there is no way to pass to know additional supported image types when the WebView is created. And ImageIO expects CGImageSourceSetAllowableTypes() to be called only once. * Source/WebCore/platform/graphics/cg/UTIRegistry.cpp: (WebCore::allowableImageTypes): * Source/WebCore/platform/graphics/cg/UTIRegistry.h: * Source/WebCore/platform/network/mac/UTIUtilities.h: * Source/WebCore/platform/network/mac/UTIUtilities.mm: (WebCore::setImageSourceAllowableTypes): * Source/WebKit/GPUProcess/GPUProcess.cpp: (WebKit::GPUProcess::initializeGPUProcess): * Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm: (WebKit::WebPage::platformInitialize): * Source/WebKit/WebProcess/WebPage/WebPage.cpp: (WebKit::m_historyItemClient): Canonical link: https://commits.webkit.org/270228@main --- .../WebCore/platform/graphics/cg/UTIRegistry.cpp | 16 +++++++++++++++- .../WebCore/platform/graphics/cg/UTIRegistry.h | 3 ++- .../WebCore/platform/network/mac/UTIUtilities.h | 4 +++- .../WebCore/platform/network/mac/UTIUtilities.mm | 15 +++++++++++++++ Source/WebKit/GPUProcess/GPUProcess.cpp | 10 +++------- .../WebProcess/WebPage/Cocoa/WebPageCocoa.mm | 4 ++++ Source/WebKit/WebProcess/WebPage/WebPage.cpp | 2 -- 7 files changed, 42 insertions(+), 12 deletions(-) diff --git a/Source/WebCore/platform/graphics/cg/UTIRegistry.cpp b/Source/WebCore/platform/graphics/cg/UTIRegistry.cpp index 4543e32ea8eb..6121586b8d29 100644 --- a/Source/WebCore/platform/graphics/cg/UTIRegistry.cpp +++ b/Source/WebCore/platform/graphics/cg/UTIRegistry.cpp @@ -146,6 +146,20 @@ ALLOW_DEPRECATED_DECLARATIONS_BEGIN ALLOW_DEPRECATED_DECLARATIONS_END } +Vector allowableImageTypes() +{ + auto allowableImageTypes = copyToVector(defaultSupportedImageTypes()); + auto additionalImageTypes = copyToVector(additionalSupportedImageTypes()); + allowableImageTypes.appendVector(additionalImageTypes); +#if HAVE(AVIF) + // AVIF might be embedded in a HEIF container. So HEIF/HEIC decoding have + // to be allowed to get AVIF decoded. + allowableImageTypes.append("public.heif"_s); + allowableImageTypes.append("public.heic"_s); +#endif + return allowableImageTypes; } -#endif +} // namespace WebCore + +#endif // USE(CG) diff --git a/Source/WebCore/platform/graphics/cg/UTIRegistry.h b/Source/WebCore/platform/graphics/cg/UTIRegistry.h index 849b0dc5b08b..738b459e5d51 100644 --- a/Source/WebCore/platform/graphics/cg/UTIRegistry.h +++ b/Source/WebCore/platform/graphics/cg/UTIRegistry.h @@ -35,8 +35,9 @@ MemoryCompactRobinHoodHashSet& additionalSupportedImageTypes(); WEBCORE_EXPORT void setAdditionalSupportedImageTypes(const Vector&); WEBCORE_EXPORT void setAdditionalSupportedImageTypesForTesting(const String&); WEBCORE_EXPORT bool isSupportedImageType(const String&); +WEBCORE_EXPORT Vector allowableImageTypes(); bool isGIFImageType(StringView); String preferredExtensionForImageType(const String& type); String MIMETypeForImageType(const String& type); -} +} // namespace WebCore diff --git a/Source/WebCore/platform/network/mac/UTIUtilities.h b/Source/WebCore/platform/network/mac/UTIUtilities.h index 306fab7f6f2d..25084a18c2c3 100644 --- a/Source/WebCore/platform/network/mac/UTIUtilities.h +++ b/Source/WebCore/platform/network/mac/UTIUtilities.h @@ -35,4 +35,6 @@ RetainPtr mimeTypeFromUTITree(CFStringRef); WEBCORE_EXPORT String UTIFromMIMEType(const String&); bool isDeclaredUTI(const String&); WEBCORE_EXPORT String UTIFromTag(const String& tagClass, const String& tag, const String& conformingToUTI); -} +WEBCORE_EXPORT void setImageSourceAllowableTypes(const Vector&); + +} // namespace WebCore diff --git a/Source/WebCore/platform/network/mac/UTIUtilities.mm b/Source/WebCore/platform/network/mac/UTIUtilities.mm index 9161fbdcdbd5..78b275130def 100644 --- a/Source/WebCore/platform/network/mac/UTIUtilities.mm +++ b/Source/WebCore/platform/network/mac/UTIUtilities.mm @@ -33,11 +33,16 @@ #import #import #import +#include #if PLATFORM(IOS_FAMILY) #import #endif +#if HAVE(CGIMAGESOURCE_WITH_SET_ALLOWABLE_TYPES) +#include +#endif + namespace WebCore { String MIMETypeFromUTI(const String& uti) @@ -149,4 +154,14 @@ String UTIFromTag(const String& tagClass, const String& tag, const String& confo return u.get(); } +void setImageSourceAllowableTypes(const Vector& supportedImageTypes) +{ +#if HAVE(CGIMAGESOURCE_WITH_SET_ALLOWABLE_TYPES) + auto allowableTypes = createNSArray(supportedImageTypes); + CGImageSourceSetAllowableTypes((__bridge CFArrayRef)allowableTypes.get()); +#else + UNUSED_PARAM(supportedImageTypes); +#endif } + +} // namespace WebCore diff --git a/Source/WebKit/GPUProcess/GPUProcess.cpp b/Source/WebKit/GPUProcess/GPUProcess.cpp index 4ef9ff2df06a..2542b0a4dc2e 100644 --- a/Source/WebKit/GPUProcess/GPUProcess.cpp +++ b/Source/WebKit/GPUProcess/GPUProcess.cpp @@ -74,13 +74,10 @@ #if PLATFORM(COCOA) #include "ArgumentCodersCocoa.h" #include +#include #include #endif -#if HAVE(CGIMAGESOURCE_WITH_SET_ALLOWABLE_TYPES) -#include -#endif - #if HAVE(SCREEN_CAPTURE_KIT) #include #endif @@ -268,9 +265,8 @@ void GPUProcess::initializeGPUProcess(GPUProcessCreationParameters&& parameters) SandboxExtension::consumePermanently(parameters.gpuToolsExtensionHandles); #endif -#if HAVE(CGIMAGESOURCE_WITH_SET_ALLOWABLE_TYPES) - auto emptyArray = adoptCF(CFArrayCreate(kCFAllocatorDefault, nullptr, 0, &kCFTypeArrayCallBacks)); - CGImageSourceSetAllowableTypes(emptyArray.get()); +#if PLATFORM(COCOA) + WebCore::setImageSourceAllowableTypes({ }); #endif #if USE(GBM) diff --git a/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm b/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm index a1938f530d92..baba092958f7 100644 --- a/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm +++ b/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm @@ -72,6 +72,8 @@ #import #import #import +#import +#import #import #import @@ -112,6 +114,8 @@ #if PLATFORM(IOS_FAMILY) setInsertionPointColor(parameters.insertionPointColor); #endif + WebCore::setAdditionalSupportedImageTypes(parameters.additionalSupportedImageTypes); + WebCore::setImageSourceAllowableTypes(WebCore::allowableImageTypes()); } void WebPage::platformDidReceiveLoadParameters(const LoadParameters& parameters) diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.cpp b/Source/WebKit/WebProcess/WebPage/WebPage.cpp index 3bf22eeb756e..44a005933760 100644 --- a/Source/WebKit/WebProcess/WebPage/WebPage.cpp +++ b/Source/WebKit/WebProcess/WebPage/WebPage.cpp @@ -336,7 +336,6 @@ #include "WKStringCF.h" #include "WebRemoteObjectRegistry.h" #include -#include #include #include #include @@ -964,7 +963,6 @@ WebPage::WebPage(PageIdentifier pageID, WebPageCreationParameters&& parameters) #if PLATFORM(COCOA) setSmartInsertDeleteEnabled(parameters.smartInsertDeleteEnabled); - WebCore::setAdditionalSupportedImageTypes(parameters.additionalSupportedImageTypes); #endif #if HAVE(APP_ACCENT_COLORS)