← All reports

Remote Snapshotting serializes images and image buffers by value

Component: WebCore Display Lists | 8a6fc5e

Source/WebCore/platform/graphics/displaylists/DisplayList.cpp

-RefPtr<const DisplayList> DisplayList::createResolvingResources(Vector<Item>&& items, std::span<const Ref<const FontBase>> fonts, std::span<const Ref<const DisplayList>> displayLists)
+RefPtr<const DisplayList> DisplayList::createResolved(Vector<Item>&& items, const ResourceCache& resourceCache)
{
for (auto& item : items) {
- bool isValid = WTF::switchOn(item, ...);
- if (!isValid || !isResolved(item))
+ if (!resourceCache.resolveItem(item) || !isResolved(item))
return nullptr;
}
return create(WTF::move(items));

Source/WebCore/platform/graphics/displaylists/DisplayListItems.h

+ const Ref<ImageType>& image() const LIFETIME_BOUND
+ {
+ RELEASE_ASSERT(isResolved());
+ return std::get<Ref<ImageType>>(m_image);
+ }
+ Variant<Ref<ImageType>, RenderingResourceIdentifier> m_image;

With remote snapshotting, the GPU process records a page into a display list and sends it as DisplayListData to the print process, which replays it into PDF output. Items such as DrawImageBuffer, DrawNativeImage and ClipToNativeImage used to hold live Ref<ImageBuffer>/Ref<const NativeImage> objects that cannot be encoded for another process, so pages with images fell back to GPU-process drawing.

The GPU process now writes each image's pixels into shared memory once and makes items refer to them by RenderingResourceIdentifier. The new ResolvableImage variant lets an item hold either the image or its identifier. The print process loads the images into a new DisplayList::ResourceCache, which rejects duplicate identifiers, wrong image kinds and pixel/size mismatches. createResolved then binds each item through resolveItem.

Several related changes ride along:

The print process now decodes far more attacker-influenced data over IPC: image pixels, sizes, scales, patterns and mesh gradients, on top of fonts and nested display lists.

Start with ResourceCache::cacheNativeImage and cacheImageBuffer: check width*height*bytesPerPixel overflow, stride and row-bytes handling, logical-size versus backing-size and scale mismatches, and zero or huge dimensions. Then follow references to identifiers that are missing, of the wrong kind, or present only in another display list (appendDisplayList). Trace nested resolution as well: patterns inside SourceBrush, SourceImage in FEImage filters, and DrawFilteredImageBuffer. ResolvableImage::image() is guarded only by RELEASE_ASSERT(isResolved()), so any item that escapes createResolved unresolved crashes the print process.

The print process maps shared memory while drawing. Check whether the sender can still write to it after the ownership transfer, a TOCTOU between validation and replay, and how handle protection and size are checked at map time.

Also review: