Title: [208575] trunk/Source/WebCore
Revision
208575
Author
commit-qu...@webkit.org
Date
2016-11-10 18:20:48 -0800 (Thu, 10 Nov 2016)

Log Message

REGRESSION(r207182): [iOS] Crash because of passing freed CFDictionaryRef to CG when decoding a sub-sampled large image
https://bugs.webkit.org/show_bug.cgi?id=164617

Patch by Said Abou-Hallawa <sabouhall...@apple.com> on 2016-11-10
Reviewed by Tim Horton.

This covered by the test fast/images/image-subsampling.html but it should
run with --guard-malloc --repeat-each=10 to show the bug or to verify the
fix.

imageSourceOptions() returns a non static RetainPtr<CFDictionaryRef> if
the subsamplingLevel is not zero. Because we are assigning the raw pointer
to a local variable in ImageDecoder::createFrameImageAtIndex(), CFRelease()
is called for the CFDictionaryRef immediately after this assignment. This
causes its memory to be freed in this case even before calling CG.

This bug does not happen if the subsamplingLevel is zero because we cache
the returned value in a static NeverDestroyed<RetainPtr<CFDictionaryRef> in
imageSourceOptions(). This cache prevents the CFDictionaryRef from being
freed in ImageDecoder::createFrameImageAtIndex() no matter where CFRelease()
is called.

The fix is hold the returned value in a RetainPtr<CFDictionaryRef>. This
will ensure the CFDictionaryRef raw pointer is valid till the end of
ImageDecoder::createFrameImageAtIndex().

* platform/graphics/cg/ImageDecoderCG.cpp:
(WebCore::ImageDecoder::createFrameImageAtIndex): Ensure the pointer is retained.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (208574 => 208575)


--- trunk/Source/WebCore/ChangeLog	2016-11-11 01:27:02 UTC (rev 208574)
+++ trunk/Source/WebCore/ChangeLog	2016-11-11 02:20:48 UTC (rev 208575)
@@ -1,3 +1,33 @@
+2016-11-10  Said Abou-Hallawa  <sabouhall...@apple.com>
+
+        REGRESSION(r207182): [iOS] Crash because of passing freed CFDictionaryRef to CG when decoding a sub-sampled large image
+        https://bugs.webkit.org/show_bug.cgi?id=164617
+
+        Reviewed by Tim Horton.
+
+        This covered by the test fast/images/image-subsampling.html but it should
+        run with --guard-malloc --repeat-each=10 to show the bug or to verify the
+        fix.
+
+        imageSourceOptions() returns a non static RetainPtr<CFDictionaryRef> if
+        the subsamplingLevel is not zero. Because we are assigning the raw pointer
+        to a local variable in ImageDecoder::createFrameImageAtIndex(), CFRelease()
+        is called for the CFDictionaryRef immediately after this assignment. This
+        causes its memory to be freed in this case even before calling CG.
+
+        This bug does not happen if the subsamplingLevel is zero because we cache
+        the returned value in a static NeverDestroyed<RetainPtr<CFDictionaryRef> in
+        imageSourceOptions(). This cache prevents the CFDictionaryRef from being
+        freed in ImageDecoder::createFrameImageAtIndex() no matter where CFRelease()
+        is called.
+
+        The fix is hold the returned value in a RetainPtr<CFDictionaryRef>. This
+        will ensure the CFDictionaryRef raw pointer is valid till the end of
+        ImageDecoder::createFrameImageAtIndex().
+
+        * platform/graphics/cg/ImageDecoderCG.cpp:
+        (WebCore::ImageDecoder::createFrameImageAtIndex): Ensure the pointer is retained.
+
 2016-11-10  Brent Fulgham  <bfulg...@apple.com>
 
         [Win][Direct2D] Add transparency layer support

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp (208574 => 208575)


--- trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp	2016-11-11 01:27:02 UTC (rev 208574)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp	2016-11-11 02:20:48 UTC (rev 208575)
@@ -343,13 +343,13 @@
 {
     LOG(Images, "ImageDecoder %p createFrameImageAtIndex %lu", this, index);
 
-    const auto* options = imageSourceOptions(subsamplingLevel, decodingMode).get();
+    RetainPtr<CFDictionaryRef> options = imageSourceOptions(subsamplingLevel, decodingMode);
     RetainPtr<CGImageRef> image;
 
     if (decodingMode == DecodingMode::OnDemand)
-        image = adoptCF(CGImageSourceCreateImageAtIndex(m_nativeDecoder.get(), index, options));
+        image = adoptCF(CGImageSourceCreateImageAtIndex(m_nativeDecoder.get(), index, options.get()));
     else
-        image = adoptCF(CGImageSourceCreateThumbnailAtIndex(m_nativeDecoder.get(), index, options));
+        image = adoptCF(CGImageSourceCreateThumbnailAtIndex(m_nativeDecoder.get(), index, options.get()));
     
 #if PLATFORM(IOS)
     // <rdar://problem/7371198> - CoreGraphics changed the default caching behaviour in iOS 4.0 to kCGImageCachingTransient
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to