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

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

Issue 2108033003: Cancel image loads if decoding failed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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) Research In Motion Limited 2009-2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 inline bool matchesCURSignature(const char* contents) 73 inline bool matchesCURSignature(const char* contents)
74 { 74 {
75 return !memcmp(contents, "\x00\x00\x02\x00", 4); 75 return !memcmp(contents, "\x00\x00\x02\x00", 4);
76 } 76 }
77 77
78 inline bool matchesBMPSignature(const char* contents) 78 inline bool matchesBMPSignature(const char* contents)
79 { 79 {
80 return !memcmp(contents, "BM", 2); 80 return !memcmp(contents, "BM", 2);
81 } 81 }
82 82
83 size_t ImageDecoder::longestSignatureLength()
84 {
85 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
86 DCHECK_EQ(14u, longestSignatureLength);
87 return 14u;
88 }
89
83 std::unique_ptr<ImageDecoder> ImageDecoder::create(const char* contents, size_t length, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) 90 std::unique_ptr<ImageDecoder> ImageDecoder::create(const char* contents, size_t length, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
84 { 91 {
85 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; 92 if (length < longestSignatureLength())
86 ASSERT(longestSignatureLength == 14);
87
88 if (length < longestSignatureLength)
89 return nullptr; 93 return nullptr;
90 94
91 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod edImageBytes() : noDecodedImageByteLimit; 95 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod edImageBytes() : noDecodedImageByteLimit;
92 96
93 if (matchesJPEGSignature(contents)) 97 if (matchesJPEGSignature(contents))
94 return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDec odedBytes)); 98 return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDec odedBytes));
95 99
96 if (matchesPNGSignature(contents)) 100 if (matchesPNGSignature(contents))
97 return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDeco dedBytes)); 101 return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDeco dedBytes));
98 102
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 387 }
384 388
385 bool ImageDecoder::hasColorProfile() const 389 bool ImageDecoder::hasColorProfile() const
386 { 390 {
387 return false; 391 return false;
388 } 392 }
389 393
390 #endif // USE(QCMSLIB) 394 #endif // USE(QCMSLIB)
391 395
392 } // namespace blink 396 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698