Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: skia/ext/skia_utils_ios.mm

Issue 923623003: Skips the processing of images larger then 88x88 in favicons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@consumer
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | skia/ext/skia_utils_ios_unittest.mm » ('j') | skia/ext/skia_utils_ios_unittest.mm » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/skia_utils_ios.mm
diff --git a/skia/ext/skia_utils_ios.mm b/skia/ext/skia_utils_ios.mm
index 3ae962cd59e55469561b3a1f1670a6096a3efc66..03f1d69920f0eaf3fe161638fcd0a7a0fe08d8d3 100644
--- a/skia/ext/skia_utils_ios.mm
+++ b/skia/ext/skia_utils_ios.mm
@@ -7,10 +7,26 @@
#import <ImageIO/ImageIO.h>
#import <UIKit/UIKit.h>
+#include "base/ios/ios_util.h"
#include "base/logging.h"
#include "base/mac/scoped_cftyperef.h"
+#include "base/macros.h"
#include "third_party/skia/include/utils/mac/SkCGUtils.h"
+namespace {
+
+const uint8 kICOHeaderMagic[4] = {0x00, 0x00, 0x01, 0x00};
+
+// Returns whether the data encodes an ico image.
+bool EncodesIcoImage(NSData* image_data) {
+ if (image_data.length < arraysize(kICOHeaderMagic))
+ return false;
+ return memcmp(kICOHeaderMagic, image_data.bytes,
+ arraysize(kICOHeaderMagic)) == 0;
+}
+
+} // namespace
+
namespace gfx {
SkBitmap CGImageToSkBitmap(CGImageRef image, CGSize size, bool is_opaque) {
@@ -74,6 +90,12 @@ UIImage* SkBitmapToUIImageWithColorSpace(const SkBitmap& skia_bitmap,
std::vector<SkBitmap> ImageDataToSkBitmaps(NSData* image_data) {
DCHECK(image_data);
+
+ // On iOS 8.1.1 |CGContextDrawImage| crashes when processing images included
+ // in .ico files that are larger then 88x88 (http://crbug.com/435068).
Justin Novosad 2015/02/19 16:10:44 then -> than
sdefresne 2015/02/19 16:46:02 Done.
+ bool skip_images_larger_than_88x88 =
+ base::ios::IsRunningOnOrLater(8, 1, 1) && EncodesIcoImage(image_data);
+
base::ScopedCFTypeRef<CFDictionaryRef> empty_dictionary(
CFDictionaryCreate(NULL, NULL, NULL, 0, NULL, NULL));
std::vector<SkBitmap> frames;
@@ -88,9 +110,12 @@ std::vector<SkBitmap> ImageDataToSkBitmaps(NSData* image_data) {
CGSize size = CGSizeMake(CGImageGetWidth(cg_image),
CGImageGetHeight(cg_image));
- const SkBitmap bitmap = CGImageToSkBitmap(cg_image, size, false);
- if (!bitmap.empty())
- frames.push_back(bitmap);
+ if (!skip_images_larger_than_88x88 ||
+ (size.width < 88 && size.height < 88)) {
Justin Novosad 2015/02/19 16:10:44 Shouldn't the conditions be '<=' instead of '<'?
sdefresne 2015/02/19 16:46:02 That's correct. Changed to use <=.
+ const SkBitmap bitmap = CGImageToSkBitmap(cg_image, size, false);
+ if (!bitmap.empty())
+ frames.push_back(bitmap);
+ }
}
DLOG_IF(WARNING, frames.size() != count) << "Only decoded " << frames.size()
« no previous file with comments | « no previous file | skia/ext/skia_utils_ios_unittest.mm » ('j') | skia/ext/skia_utils_ios_unittest.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698