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

Side by Side Diff: third_party/WebKit/Source/platform/exported/WebImage.cpp

Issue 2173873003: Cancel image loads if decoding failed (attempt #2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix UAF Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 28 matching lines...) Expand all
39 #include "wtf/PassRefPtr.h" 39 #include "wtf/PassRefPtr.h"
40 #include "wtf/Vector.h" 40 #include "wtf/Vector.h"
41 #include <algorithm> 41 #include <algorithm>
42 #include <memory> 42 #include <memory>
43 43
44 namespace blink { 44 namespace blink {
45 45
46 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize) 46 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize)
47 { 47 {
48 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); 48 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data);
49 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), Im ageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); 49 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(ImageDecoder::det ermineImageType(*buffer.get()), ImageDecoder::AlphaPremultiplied, ImageDecoder:: GammaAndColorProfileIgnored));
50 if (!decoder) 50 if (!decoder)
51 return WebImage(); 51 return WebImage();
52 52
53 decoder->setData(buffer.get(), true); 53 decoder->setData(buffer.get(), true);
54 if (!decoder->isSizeAvailable()) 54 if (!decoder->isSizeAvailable())
55 return WebImage(); 55 return WebImage();
56 56
57 // Frames are arranged by decreasing size, then decreasing bit depth. 57 // Frames are arranged by decreasing size, then decreasing bit depth.
58 // Pick the frame closest to |desiredSize|'s area without being smaller, 58 // Pick the frame closest to |desiredSize|'s area without being smaller,
59 // which has the highest bit depth. 59 // which has the highest bit depth.
(...skipping 23 matching lines...) Expand all
83 83
84 return WebImage(frame->bitmap()); 84 return WebImage(frame->bitmap());
85 } 85 }
86 86
87 WebVector<WebImage> WebImage::framesFromData(const WebData& data) 87 WebVector<WebImage> WebImage::framesFromData(const WebData& data)
88 { 88 {
89 // This is to protect from malicious images. It should be big enough that it 's never hit in pracice. 89 // This is to protect from malicious images. It should be big enough that it 's never hit in pracice.
90 const size_t maxFrameCount = 8; 90 const size_t maxFrameCount = 8;
91 91
92 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); 92 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data);
93 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), Im ageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); 93 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(ImageDecoder::det ermineImageType(*buffer.get()), ImageDecoder::AlphaPremultiplied, ImageDecoder:: GammaAndColorProfileIgnored));
94 if (!decoder) 94 if (!decoder)
95 return WebVector<WebImage>(); 95 return WebVector<WebImage>();
96 96
97 decoder->setData(buffer.get(), true); 97 decoder->setData(buffer.get(), true);
98 if (!decoder->isSizeAvailable()) 98 if (!decoder->isSizeAvailable())
99 return WebVector<WebImage>(); 99 return WebVector<WebImage>();
100 100
101 // Frames are arranged by decreasing size, then decreasing bit depth. 101 // Frames are arranged by decreasing size, then decreasing bit depth.
102 // Keep the first frame at every size, has the highest bit depth. 102 // Keep the first frame at every size, has the highest bit depth.
103 const size_t frameCount = decoder->frameCount(); 103 const size_t frameCount = decoder->frameCount();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 WebImage::WebImage(const PassRefPtr<Image>& image) 145 WebImage::WebImage(const PassRefPtr<Image>& image)
146 { 146 {
147 if (!image) 147 if (!image)
148 return; 148 return;
149 149
150 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame()) 150 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame())
151 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); 151 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode);
152 } 152 }
153 153
154 } // namespace blink 154 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698