Changeset 277255 in webkit


Ignore:
Timestamp:
May 9, 2021, 6:48:09 PM (4 years ago)
Author:
weinig@apple.com
Message:

Add back protection of the pixel buffer in ImageBufferCGBackend::toCFData removed in r277237
https://bugs.webkit.org/show_bug.cgi?id=225574

Reviewed by Darin Adler.

In r277237, I accidentally removed a RefPtr<Uint8ClampedArray> protectedPixelArray
in ImageBufferCGBackend::toCFData that was needed to avoided crashing in some cases
when running fast/canvas/canvas-toDataURL-jpeg-crash.html.

Since it wasn't super clear what it was doing, this switches to using the more idiomatic
method of keeping the data alive in a CGDataProviderRef by passing the leaked image data
as the context and derefing in the callback lambda.

Just to be consistent, I went to other callers of CGDataProviderCreateWithData and
updated them to be idiomatically consistent.

  • platform/graphics/cg/GraphicsContextGLCG.cpp:

(WebCore::GraphicsContextGLOpenGL::paintToCanvas):
(WebCore::releaseImageData): Deleted.

  • platform/graphics/cg/ImageBufferCGBackend.cpp:

(WebCore::ImageBufferCGBackend::toCFData const):

  • platform/graphics/cg/ImageBufferCGBitmapBackend.cpp:

(WebCore::ImageBufferCGBitmapBackend::create):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r277254 r277255  
     12021-05-09  Sam Weinig  <weinig@apple.com>
     2
     3        Add back protection of the pixel buffer in ImageBufferCGBackend::toCFData removed in r277237
     4        https://bugs.webkit.org/show_bug.cgi?id=225574
     5
     6        Reviewed by Darin Adler.
     7
     8        In r277237, I accidentally removed a `RefPtr<Uint8ClampedArray> protectedPixelArray`
     9        in ImageBufferCGBackend::toCFData that was needed to avoided crashing in some cases
     10        when running fast/canvas/canvas-toDataURL-jpeg-crash.html.
     11
     12        Since it wasn't super clear what it was doing, this switches to using the more idiomatic
     13        method of keeping the data alive in a CGDataProviderRef by passing the leaked image data
     14        as the context and derefing in the callback lambda.
     15
     16        Just to be consistent, I went to other callers of CGDataProviderCreateWithData and
     17        updated them to be idiomatically consistent.
     18
     19        * platform/graphics/cg/GraphicsContextGLCG.cpp:
     20        (WebCore::GraphicsContextGLOpenGL::paintToCanvas):
     21        (WebCore::releaseImageData): Deleted.
     22        * platform/graphics/cg/ImageBufferCGBackend.cpp:
     23        (WebCore::ImageBufferCGBackend::toCFData const):
     24        * platform/graphics/cg/ImageBufferCGBitmapBackend.cpp:
     25        (WebCore::ImageBufferCGBitmapBackend::create):
     26
    1272021-05-09  Lauro Moura  <lmoura@igalia.com>
    228
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp

    r277237 r277255  
    507507}
    508508
    509 static void releaseImageData(void* imageData, const void*, size_t)
    510 {
    511     reinterpret_cast<ImageData*>(imageData)->deref();
    512 }
    513 
    514509void GraphicsContextGLOpenGL::paintToCanvas(const GraphicsContextGLAttributes& sourceContextAttributes, Ref<ImageData>&& imageData, const IntSize& canvasSize, GraphicsContext& context)
    515510{
     
    529524    auto imageSize = imageData->size();
    530525    int rowBytes = imageSize.width() * 4;
    531         size_t dataSize = rowBytes * imageSize.height();
     526    size_t dataSize = rowBytes * imageSize.height();
    532527    uint8_t* imagePixels = imageData->data().data();
    533         verifyImageBufferIsBigEnough(imagePixels, dataSize);
    534     RetainPtr<CGDataProviderRef> dataProvider = adoptCF(CGDataProviderCreateWithData(&imageData.leakRef(), imagePixels, dataSize, releaseImageData));
    535 
    536     auto image = NativeImage::create(adoptCF(CGImageCreate(imageSize.width(), imageSize.height(), 8, 32, rowBytes, sRGBColorSpaceRef(), bitmapInfo,
    537         dataProvider.get(), 0, false, kCGRenderingIntentDefault)));
     528    verifyImageBufferIsBigEnough(imagePixels, dataSize);
     529    auto dataProvider = adoptCF(CGDataProviderCreateWithData(&imageData.leakRef(), imagePixels, dataSize, [] (void* context, const void*, size_t) {
     530        reinterpret_cast<ImageData*>(context)->deref();
     531    }));
     532
     533    auto image = NativeImage::create(adoptCF(CGImageCreate(imageSize.width(), imageSize.height(), 8, 32, rowBytes, sRGBColorSpaceRef(), bitmapInfo, dataProvider.get(), 0, false, kCGRenderingIntentDefault)));
    538534
    539535    // CSS styling may cause the canvas's content to be resized on
  • trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp

    r277237 r277255  
    192192            return nullptr;
    193193
    194         auto protectedPixelArray = makeRef(imageData->data());
    195         size_t dataSize = protectedPixelArray->byteLength();
    196         IntSize pixelArrayDimensions = imageData->size();
    197 
    198         verifyImageBufferIsBigEnough(protectedPixelArray->data(), dataSize);
    199         auto dataProvider = adoptCF(CGDataProviderCreateWithData(nullptr, protectedPixelArray->data(), dataSize, nullptr));
     194        auto& pixelArray = imageData->data();
     195        auto dataSize = pixelArray.byteLength();
     196        auto pixelArrayDimensions = imageData->size();
     197
     198        verifyImageBufferIsBigEnough(pixelArray.data(), dataSize);
     199
     200        auto dataProvider = adoptCF(CGDataProviderCreateWithData(imageData.leakRef(), pixelArray.data(), dataSize, [] (void* context, const void*, size_t) {
     201            reinterpret_cast<ImageData*>(context)->deref();
     202        }));
     203       
    200204        if (!dataProvider)
    201205            return nullptr;
  • trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp

    r275905 r277255  
    8888    auto context = makeUnique<GraphicsContext>(cgContext.get());
    8989
    90     const auto releaseImageData = [] (void*, const void* data, size_t) {
     90    auto dataProvider = adoptCF(CGDataProviderCreateWithData(nullptr, data, numBytes, [] (void*, const void* data, size_t) {
    9191        fastFree(const_cast<void*>(data));
    92     };
    93 
    94     auto dataProvider = adoptCF(CGDataProviderCreateWithData(0, data, numBytes, releaseImageData));
     92    }));
    9593
    9694    return std::unique_ptr<ImageBufferCGBitmapBackend>(new ImageBufferCGBitmapBackend(parameters, data, WTFMove(dataProvider), WTFMove(context)));
Note: See TracChangeset for help on using the changeset viewer.