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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.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, 5 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 bool decoded = m_frameGenerator->decodeToYUV(m_data.get(), m_frameIndex, siz eInfo.fSizes, planes, sizeInfo.fWidthBytes); 115 bool decoded = m_frameGenerator->decodeToYUV(m_data.get(), m_frameIndex, siz eInfo.fSizes, planes, sizeInfo.fWidthBytes);
116 PlatformInstrumentation::didDecodeLazyPixelRef(); 116 PlatformInstrumentation::didDecodeLazyPixelRef();
117 117
118 return decoded; 118 return decoded;
119 } 119 }
120 120
121 SkImageGenerator* DecodingImageGenerator::create(SkData* data) 121 SkImageGenerator* DecodingImageGenerator::create(SkData* data)
122 { 122 {
123 // We just need the size of the image, so we have to temporarily create an I mageDecoder. Since 123 // We just need the size of the image, so we have to temporarily create an I mageDecoder. Since
124 // we only need the size, it doesn't really matter about premul or not, or g amma settings. 124 // we only need the size, it doesn't really matter about premul or not, or g amma settings.
125 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create(static_cast<con st char*>(data->data()), data->size(), 125 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create(ImageDecoder::d etermineImageType(static_cast<const char*>(data->data()), data->size()),
126 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileAppl ied); 126 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileAppl ied);
127 if (!decoder) 127 if (!decoder)
128 return 0; 128 return 0;
129 129
130 // Blink does not know Skia has already adopted |data|. 130 // Blink does not know Skia has already adopted |data|.
131 WTF::adopted(data); 131 WTF::adopted(data);
132 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(data); 132 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(data);
133 decoder->setData(segmentReader.get(), true); 133 decoder->setData(segmentReader.get(), true);
134 if (!decoder->isSizeAvailable()) 134 if (!decoder->isSizeAvailable())
135 return 0; 135 return 0;
136 136
137 const IntSize size = decoder->size(); 137 const IntSize size = decoder->size();
138 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh t()); 138 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh t());
139 139
140 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak e(size.width(), size.height()), false); 140 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak e(size.width(), size.height()), false);
141 if (!frame) 141 if (!frame)
142 return 0; 142 return 0;
143 143
144 return new DecodingImageGenerator(frame, info, segmentReader.release(), true , 0); 144 return new DecodingImageGenerator(frame, info, segmentReader.release(), true , 0);
145 } 145 }
146 146
147 } // namespace blink 147 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698