Bug 164617 - REGRESSION(r207182): [iOS] Crash because of passing freed CFDictionaryRef to CG when decoding a sub-sampled large image
Summary: REGRESSION(r207182): [iOS] Crash because of passing freed CFDictionaryRef to ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Said Abou-Hallawa
URL:
Keywords: InRadar, Regression
Depends on:
Blocks:
 
Reported: 2016-11-10 14:11 PST by Said Abou-Hallawa
Modified: 2016-11-10 18:23 PST (History)
2 users (show)

See Also:


Attachments
Patch (5.20 KB, patch)
2016-11-10 16:53 PST, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (3.25 KB, patch)
2016-11-10 17:02 PST, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Said Abou-Hallawa 2016-11-10 14:11:36 PST
On iOS image sub-sampling is enabled by default, WebCore::imageSourceOptions() creates a new dictionary for the image options every time it is called.

Because ImageDecoder::createFrameImageAtIndex() takes the raw pointer of the output of imageSourceOptions(), CFRelease() is called for the returned retain pointer. This happens immediately after assigning the raw pointer to the local variable.  This causes the CFDictionaryRef to be freed before passing it to CGImageSourceCreateImageAtIndex().

    CFDictionaryRef options = imageSourceOptions(subsamplingLevel, decodingMode).get();
    RetainPtr<CGImageRef> image = adoptCF(CGImageSourceCreateImageAtIndex(m_nativeDecoder.get(), index, options));

The original code was not getting the raw pointer into a local variable. Instead it was passing it directly to  CGImageSourceCreateImageAtIndex(). This prevents calling CFRelease() before CGImageSourceCreateImageAtIndex returns.

    RetainPtr<CGImageRef> image = adoptCF(CGImageSourceCreateImageAtIndex(m_nativeDecoder.get(), index, imageSourceOptions(subsamplingLevel).get()));
Comment 1 Said Abou-Hallawa 2016-11-10 14:12:43 PST
<rdar://problem/28907947>
Comment 2 Said Abou-Hallawa 2016-11-10 16:53:37 PST
Created attachment 294443 [details]
Patch
Comment 3 Tim Horton 2016-11-10 16:59:16 PST
Comment on attachment 294443 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=294443&action=review

> Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp:65
> +    CFDictionaryAddValue(options.get(), kCGImageSourceShouldCache, kCFBooleanTrue);

Why swap to Add? Set is a tiny bit cheaper (I think?) and we know that each key will only be used once.
Comment 4 Said Abou-Hallawa 2016-11-10 17:02:08 PST
Created attachment 294444 [details]
Patch
Comment 5 WebKit Commit Bot 2016-11-10 18:23:53 PST
Comment on attachment 294444 [details]
Patch

Clearing flags on attachment: 294444

Committed r208575: <http://trac.webkit.org/changeset/208575>
Comment 6 WebKit Commit Bot 2016-11-10 18:23:57 PST
All reviewed patches have been landed.  Closing bug.