Changeset 215729 in webkit


Ignore:
Timestamp:
Apr 25, 2017 5:35:18 AM (7 years ago)
Author:
magomez@igalia.com
Message:

Image decoders must have private constructors to avoid refcount misuse: ASSERTION FAILED: m_deletionHasBegun when destroying ImageDecoder
https://bugs.webkit.org/show_bug.cgi?id=171211

Reviewed by Carlos Garcia Campos.

Add a create method to each of the decoders and set their constructors as private. Change
ICOImageDecoder to store its internal PNG decoders as RefPtr and use the new create method, and
change ImageDecoder to use the create methods as well.

Covered by existent tests.

  • platform/image-decoders/ImageDecoder.cpp:

(WebCore::ImageDecoder::create):

  • platform/image-decoders/bmp/BMPImageDecoder.h:
  • platform/image-decoders/gif/GIFImageDecoder.h:
  • platform/image-decoders/ico/ICOImageDecoder.cpp:

(WebCore::ICOImageDecoder::decodeAtIndex):

  • platform/image-decoders/ico/ICOImageDecoder.h:
  • platform/image-decoders/jpeg/JPEGImageDecoder.h:
  • platform/image-decoders/png/PNGImageDecoder.h:
  • platform/image-decoders/webp/WEBPImageDecoder.h:
Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r215728 r215729  
     12017-04-25  Miguel Gomez  <magomez@igalia.com>
     2
     3        Image decoders must have private constructors to avoid refcount misuse: ASSERTION FAILED: m_deletionHasBegun when destroying ImageDecoder
     4        https://bugs.webkit.org/show_bug.cgi?id=171211
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Add a create method to each of the decoders and set their constructors as private. Change
     9        ICOImageDecoder to store its internal PNG decoders as RefPtr and use the new create method, and
     10        change ImageDecoder to use the create methods as well.
     11
     12        Covered by existent tests.
     13
     14        * platform/image-decoders/ImageDecoder.cpp:
     15        (WebCore::ImageDecoder::create):
     16        * platform/image-decoders/bmp/BMPImageDecoder.h:
     17        * platform/image-decoders/gif/GIFImageDecoder.h:
     18        * platform/image-decoders/ico/ICOImageDecoder.cpp:
     19        (WebCore::ICOImageDecoder::decodeAtIndex):
     20        * platform/image-decoders/ico/ICOImageDecoder.h:
     21        * platform/image-decoders/jpeg/JPEGImageDecoder.h:
     22        * platform/image-decoders/png/PNGImageDecoder.h:
     23        * platform/image-decoders/webp/WEBPImageDecoder.h:
     24
    1252017-04-25  Myles C. Maxfield  <mmaxfield@apple.com>
    226
  • trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp

    r215710 r215729  
    108108
    109109    if (matchesGIFSignature(contents))
    110         return adoptRef(*new GIFImageDecoder(alphaOption, gammaAndColorProfileOption));
     110        return GIFImageDecoder::create(alphaOption, gammaAndColorProfileOption);
    111111
    112112    if (matchesPNGSignature(contents))
    113         return adoptRef(*new PNGImageDecoder(alphaOption, gammaAndColorProfileOption));
     113        return PNGImageDecoder::create(alphaOption, gammaAndColorProfileOption);
    114114
    115115    if (matchesICOSignature(contents) || matchesCURSignature(contents))
    116         return adoptRef(*new ICOImageDecoder(alphaOption, gammaAndColorProfileOption));
     116        return ICOImageDecoder::create(alphaOption, gammaAndColorProfileOption);
    117117
    118118    if (matchesJPEGSignature(contents))
    119         return adoptRef(*new JPEGImageDecoder(alphaOption, gammaAndColorProfileOption));
     119        return JPEGImageDecoder::create(alphaOption, gammaAndColorProfileOption);
    120120
    121121#if USE(WEBP)
    122122    if (matchesWebPSignature(contents))
    123         return adoptRef(*new WEBPImageDecoder(alphaOption, gammaAndColorProfileOption));
     123        return WEBPImageDecoder::create(alphaOption, gammaAndColorProfileOption);
    124124#endif
    125125
    126126    if (matchesBMPSignature(contents))
    127         return adoptRef(*new BMPImageDecoder(alphaOption, gammaAndColorProfileOption));
     127        return BMPImageDecoder::create(alphaOption, gammaAndColorProfileOption);
    128128
    129129    return nullptr;
  • trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h

    r215710 r215729  
    3838    class BMPImageDecoder final : public ImageDecoder {
    3939    public:
    40         BMPImageDecoder(AlphaOption, GammaAndColorProfileOption);
     40        static Ref<ImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     41        {
     42            return adoptRef(*new BMPImageDecoder(alphaOption, gammaAndColorProfileOption));
     43        }
    4144
    4245        // ImageDecoder
     
    5154
    5255    private:
     56        BMPImageDecoder(AlphaOption, GammaAndColorProfileOption);
     57
    5358        inline uint32_t readUint32(int offset) const
    5459        {
  • trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h

    r215710 r215729  
    3636    class GIFImageDecoder final : public ImageDecoder {
    3737    public:
    38         GIFImageDecoder(AlphaOption, GammaAndColorProfileOption);
     38        static Ref<ImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     39        {
     40            return adoptRef(*new GIFImageDecoder(alphaOption, gammaAndColorProfileOption));
     41        }
     42
    3943        virtual ~GIFImageDecoder();
    4044
     
    6165
    6266    private:
     67        GIFImageDecoder(AlphaOption, GammaAndColorProfileOption);
     68
    6369        // If the query is GIFFullQuery, decodes the image up to (but not
    6470        // including) |haltAtFrame|.  Otherwise, decodes as much as is needed to
  • trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp

    r215710 r215729  
    217217
    218218    if (!m_pngDecoders[index]) {
    219         m_pngDecoders[index] = std::make_unique<
    220             PNGImageDecoder>(m_premultiplyAlpha ? AlphaOption::Premultiplied : AlphaOption::NotPremultiplied,
    221                 m_ignoreGammaAndColorProfile ? GammaAndColorProfileOption::Ignored : GammaAndColorProfileOption::Applied);
     219        m_pngDecoders[index] = PNGImageDecoder::create(m_premultiplyAlpha ? AlphaOption::Premultiplied : AlphaOption::NotPremultiplied, m_ignoreGammaAndColorProfile ? GammaAndColorProfileOption::Ignored : GammaAndColorProfileOption::Applied);
    222220        setDataForPNGDecoderAtIndex(index);
    223221    }
  • trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h

    r215710 r215729  
    3434
    3535namespace WebCore {
    36 
    37     class PNGImageDecoder;
    38 
    3936    // This class decodes the ICO and CUR image formats.
    4037    class ICOImageDecoder final : public ImageDecoder {
    4138    public:
    42         ICOImageDecoder(AlphaOption, GammaAndColorProfileOption);
     39        static Ref<ImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     40        {
     41            return adoptRef(*new ICOImageDecoder(alphaOption, gammaAndColorProfileOption));
     42        }
     43
    4344        virtual ~ICOImageDecoder();
    4445
     
    7677            uint32_t m_imageOffset;
    7778        };
     79
     80        ICOImageDecoder(AlphaOption, GammaAndColorProfileOption);
    7881
    7982        // Returns true if |a| is a preferable icon entry to |b|.
     
    142145        typedef Vector<std::unique_ptr<BMPImageReader>> BMPReaders;
    143146        BMPReaders m_bmpReaders;
    144         typedef Vector<std::unique_ptr<PNGImageDecoder>> PNGDecoders;
     147        typedef Vector<RefPtr<ImageDecoder>> PNGDecoders;
    145148        PNGDecoders m_pngDecoders;
    146149
  • trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h

    r215710 r215729  
    4444    class JPEGImageDecoder final : public ImageDecoder {
    4545    public:
    46         JPEGImageDecoder(AlphaOption, GammaAndColorProfileOption);
     46        static Ref<ImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     47        {
     48            return adoptRef(*new JPEGImageDecoder(alphaOption, gammaAndColorProfileOption));
     49        }
     50
    4751        virtual ~JPEGImageDecoder();
    4852
     
    6973
    7074    private:
     75        JPEGImageDecoder(AlphaOption, GammaAndColorProfileOption);
     76
    7177        // Decodes the image.  If |onlySize| is true, stops decoding after
    7278        // calculating the image size.  If decoding fails but there is no more
  • trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.h

    r215710 r215729  
    3838    class PNGImageDecoder final : public ImageDecoder {
    3939    public:
    40         PNGImageDecoder(AlphaOption, GammaAndColorProfileOption);
     40        static Ref<ImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     41        {
     42            return adoptRef(*new PNGImageDecoder(alphaOption, gammaAndColorProfileOption));
     43        }
     44
    4145        virtual ~PNGImageDecoder();
    4246
     
    8690
    8791    private:
     92        PNGImageDecoder(AlphaOption, GammaAndColorProfileOption);
     93
    8894        // Decodes the image.  If |onlySize| is true, stops decoding after
    8995        // calculating the image size.  If decoding fails but there is no more
  • trunk/Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.h

    r215710 r215729  
    3939class WEBPImageDecoder final : public ImageDecoder {
    4040public:
    41     WEBPImageDecoder(AlphaOption, GammaAndColorProfileOption);
     41    static Ref<ImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     42    {
     43        return adoptRef(*new WEBPImageDecoder(alphaOption, gammaAndColorProfileOption));
     44    }
     45
    4246    virtual ~WEBPImageDecoder();
    4347
     
    4751
    4852private:
     53    WEBPImageDecoder(AlphaOption, GammaAndColorProfileOption);
     54
    4955    bool decode(bool onlySize);
    5056
Note: See TracChangeset for help on using the changeset viewer.