Skip to content

Commit

Permalink
[GPU Process] Ensure that only supported image decoders run in the We…
Browse files Browse the repository at this point in the history
…bProcess

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
  • Loading branch information
shallawa authored and Said Abou-Hallawa committed Nov 4, 2023
1 parent 0cf3ba9 commit e2934b9
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 12 deletions.
16 changes: 15 additions & 1 deletion Source/WebCore/platform/graphics/cg/UTIRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ ALLOW_DEPRECATED_DECLARATIONS_BEGIN
ALLOW_DEPRECATED_DECLARATIONS_END
}

Vector<String> 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)
3 changes: 2 additions & 1 deletion Source/WebCore/platform/graphics/cg/UTIRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ MemoryCompactRobinHoodHashSet<String>& additionalSupportedImageTypes();
WEBCORE_EXPORT void setAdditionalSupportedImageTypes(const Vector<String>&);
WEBCORE_EXPORT void setAdditionalSupportedImageTypesForTesting(const String&);
WEBCORE_EXPORT bool isSupportedImageType(const String&);
WEBCORE_EXPORT Vector<String> allowableImageTypes();
bool isGIFImageType(StringView);
String preferredExtensionForImageType(const String& type);
String MIMETypeForImageType(const String& type);

}
} // namespace WebCore
4 changes: 3 additions & 1 deletion Source/WebCore/platform/network/mac/UTIUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ RetainPtr<CFStringRef> 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<String>&);

} // namespace WebCore
15 changes: 15 additions & 0 deletions Source/WebCore/platform/network/mac/UTIUtilities.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@
#import <wtf/TinyLRUCache.h>
#import <wtf/cf/TypeCastsCF.h>
#import <wtf/text/WTFString.h>
#include <wtf/cocoa/VectorCocoa.h>

#if PLATFORM(IOS_FAMILY)
#import <MobileCoreServices/MobileCoreServices.h>
#endif

#if HAVE(CGIMAGESOURCE_WITH_SET_ALLOWABLE_TYPES)
#include <pal/spi/cg/ImageIOSPI.h>
#endif

namespace WebCore {

String MIMETypeFromUTI(const String& uti)
Expand Down Expand Up @@ -149,4 +154,14 @@ String UTIFromTag(const String& tagClass, const String& tag, const String& confo
return u.get();
}

void setImageSourceAllowableTypes(const Vector<String>& supportedImageTypes)
{
#if HAVE(CGIMAGESOURCE_WITH_SET_ALLOWABLE_TYPES)
auto allowableTypes = createNSArray(supportedImageTypes);
CGImageSourceSetAllowableTypes((__bridge CFArrayRef)allowableTypes.get());
#else
UNUSED_PARAM(supportedImageTypes);
#endif
}

} // namespace WebCore
10 changes: 3 additions & 7 deletions Source/WebKit/GPUProcess/GPUProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,10 @@
#if PLATFORM(COCOA)
#include "ArgumentCodersCocoa.h"
#include <WebCore/CoreAudioSharedUnit.h>
#include <WebCore/UTIUtilities.h>
#include <WebCore/VP9UtilitiesCocoa.h>
#endif

#if HAVE(CGIMAGESOURCE_WITH_SET_ALLOWABLE_TYPES)
#include <pal/spi/cg/ImageIOSPI.h>
#endif

#if HAVE(SCREEN_CAPTURE_KIT)
#include <WebCore/ScreenCaptureKitCaptureSource.h>
#endif
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
#import <WebCore/RenderLayer.h>
#import <WebCore/RenderedDocumentMarker.h>
#import <WebCore/TextIterator.h>
#import <WebCore/UTIRegistry.h>
#import <WebCore/UTIUtilities.h>
#import <pal/spi/cocoa/LaunchServicesSPI.h>
#import <pal/spi/cocoa/QuartzCoreSPI.h>

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions Source/WebKit/WebProcess/WebPage/WebPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@
#include "WKStringCF.h"
#include "WebRemoteObjectRegistry.h"
#include <WebCore/LegacyWebArchive.h>
#include <WebCore/UTIRegistry.h>
#include <pal/spi/cg/ImageIOSPI.h>
#include <wtf/MachSendRight.h>
#include <wtf/spi/darwin/SandboxSPI.h>
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e2934b9

Please sign in to comment.