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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h

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) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 enum AlphaOption { 87 enum AlphaOption {
88 AlphaPremultiplied, 88 AlphaPremultiplied,
89 AlphaNotPremultiplied 89 AlphaNotPremultiplied
90 }; 90 };
91 91
92 enum GammaAndColorProfileOption { 92 enum GammaAndColorProfileOption {
93 GammaAndColorProfileApplied, 93 GammaAndColorProfileApplied,
94 GammaAndColorProfileIgnored 94 GammaAndColorProfileIgnored
95 }; 95 };
96 96
97 enum class SniffResult {
98 JPEG,
99 PNG,
100 GIF,
101 WEBP,
102 ICO,
103 BMP,
104 InsufficientData,
105 Invalid
106 };
107
108 static SniffResult determineImageType(const char* data, size_t length);
109 static SniffResult determineImageType(const SharedBuffer&);
110 static SniffResult determineImageType(const SegmentReader&);
111
97 ImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption colorOption s, size_t maxDecodedBytes) 112 ImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption colorOption s, size_t maxDecodedBytes)
98 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied) 113 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied)
99 , m_ignoreGammaAndColorProfile(colorOptions == GammaAndColorProfileIgnor ed) 114 , m_ignoreGammaAndColorProfile(colorOptions == GammaAndColorProfileIgnor ed)
100 , m_maxDecodedBytes(maxDecodedBytes) 115 , m_maxDecodedBytes(maxDecodedBytes)
101 , m_sizeAvailable(false) 116 , m_sizeAvailable(false)
102 , m_isAllDataReceived(false) 117 , m_isAllDataReceived(false)
103 , m_failed(false) { } 118 , m_failed(false) { }
104 119
105 virtual ~ImageDecoder() { } 120 virtual ~ImageDecoder() { }
106 121
107 // Returns a caller-owned decoder of the appropriate type. Returns 0 if 122 // Returns a caller-owned decoder of the appropriate type. Returns 0 if
108 // we can't sniff a supported type from the provided data (possibly 123 // we can't sniff a supported type from the provided data (possibly
109 // because there isn't enough data yet). 124 // because there isn't enough data yet).
110 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). 125 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes().
111 static std::unique_ptr<ImageDecoder> create(const char* data, size_t length, AlphaOption, GammaAndColorProfileOption); 126 static std::unique_ptr<ImageDecoder> create(SniffResult, AlphaOption, GammaA ndColorProfileOption);
112 static std::unique_ptr<ImageDecoder> create(const SharedBuffer&, AlphaOption , GammaAndColorProfileOption);
113 static std::unique_ptr<ImageDecoder> create(const SegmentReader&, AlphaOptio n, GammaAndColorProfileOption);
114 127
115 virtual String filenameExtension() const = 0; 128 virtual String filenameExtension() const = 0;
116 129
117 bool isAllDataReceived() const { return m_isAllDataReceived; } 130 bool isAllDataReceived() const { return m_isAllDataReceived; }
118 131
119 void setData(PassRefPtr<SegmentReader> data, bool allDataReceived) 132 void setData(PassRefPtr<SegmentReader> data, bool allDataReceived)
120 { 133 {
121 if (m_failed) 134 if (m_failed)
122 return; 135 return;
123 m_data = data; 136 m_data = data;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 bool m_failed; 344 bool m_failed;
332 345
333 #if USE(QCMSLIB) 346 #if USE(QCMSLIB)
334 QCMSTransformUniquePtr m_sourceToOutputDeviceColorTransform; 347 QCMSTransformUniquePtr m_sourceToOutputDeviceColorTransform;
335 #endif 348 #endif
336 }; 349 };
337 350
338 } // namespace blink 351 } // namespace blink
339 352
340 #endif 353 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698