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

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

Issue 1571233003: Fix errors caused by unsafe conversions to/from size_t (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: improved ALLOW_NUMERIC_ARG_TYPES_PROMOTABLE_TO Created 4 years, 11 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 14 matching lines...) Expand all
25 #include "platform/image-decoders/bmp/BMPImageDecoder.h" 25 #include "platform/image-decoders/bmp/BMPImageDecoder.h"
26 #include "platform/image-decoders/gif/GIFImageDecoder.h" 26 #include "platform/image-decoders/gif/GIFImageDecoder.h"
27 #include "platform/image-decoders/ico/ICOImageDecoder.h" 27 #include "platform/image-decoders/ico/ICOImageDecoder.h"
28 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" 28 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h"
29 #include "platform/image-decoders/png/PNGImageDecoder.h" 29 #include "platform/image-decoders/png/PNGImageDecoder.h"
30 #include "platform/image-decoders/webp/WEBPImageDecoder.h" 30 #include "platform/image-decoders/webp/WEBPImageDecoder.h"
31 #include "wtf/PassOwnPtr.h" 31 #include "wtf/PassOwnPtr.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 static unsigned copyFromSharedBuffer(char* buffer, unsigned bufferLength, const SharedBuffer& sharedBuffer, unsigned offset) 35 static size_t copyFromSharedBuffer(char* buffer, size_t bufferLength, const Shar edBuffer& sharedBuffer, size_t offset)
36 { 36 {
37 unsigned bytesExtracted = 0; 37 size_t bytesExtracted = 0;
38 const char* moreData; 38 const char* moreData;
39 while (unsigned moreDataLength = sharedBuffer.getSomeData(moreData, offset)) { 39 while (size_t moreDataLength = sharedBuffer.getSomeData(moreData, offset)) {
40 unsigned bytesToCopy = std::min(bufferLength - bytesExtracted, moreDataL ength); 40 size_t bytesToCopy = std::min(bufferLength - bytesExtracted, moreDataLen gth);
41 memcpy(buffer + bytesExtracted, moreData, bytesToCopy); 41 memcpy(buffer + bytesExtracted, moreData, bytesToCopy);
42 bytesExtracted += bytesToCopy; 42 bytesExtracted += bytesToCopy;
43 if (bytesExtracted == bufferLength) 43 if (bytesExtracted == bufferLength)
44 break; 44 break;
45 offset += bytesToCopy; 45 offset += bytesToCopy;
46 } 46 }
47 return bytesExtracted; 47 return bytesExtracted;
48 } 48 }
49 49
50 inline bool matchesJPEGSignature(char* contents) 50 inline bool matchesJPEGSignature(char* contents)
(...skipping 26 matching lines...) Expand all
77 return !memcmp(contents, "\x00\x00\x02\x00", 4); 77 return !memcmp(contents, "\x00\x00\x02\x00", 4);
78 } 78 }
79 79
80 inline bool matchesBMPSignature(char* contents) 80 inline bool matchesBMPSignature(char* contents)
81 { 81 {
82 return !memcmp(contents, "BM", 2); 82 return !memcmp(contents, "BM", 2);
83 } 83 }
84 84
85 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOpt ion alphaOption, GammaAndColorProfileOption colorOptions) 85 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOpt ion alphaOption, GammaAndColorProfileOption colorOptions)
86 { 86 {
87 const unsigned longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; 87 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
88 ASSERT(longestSignatureLength == 14); 88 ASSERT(longestSignatureLength == 14);
89 89
90 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod edImageBytes() : noDecodedImageByteLimit; 90 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod edImageBytes() : noDecodedImageByteLimit;
91 91
92 char contents[longestSignatureLength]; 92 char contents[longestSignatureLength];
93 if (copyFromSharedBuffer(contents, longestSignatureLength, data, 0) < longes tSignatureLength) 93 if (copyFromSharedBuffer(contents, longestSignatureLength, data, 0) < longes tSignatureLength)
94 return nullptr; 94 return nullptr;
95 95
96 if (matchesJPEGSignature(contents)) 96 if (matchesJPEGSignature(contents))
97 return adoptPtr(new JPEGImageDecoder(alphaOption, colorOptions, maxDecod edBytes)); 97 return adoptPtr(new JPEGImageDecoder(alphaOption, colorOptions, maxDecod edBytes));
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 return m_planes[i]; 265 return m_planes[i];
266 } 266 }
267 267
268 size_t ImagePlanes::rowBytes(int i) const 268 size_t ImagePlanes::rowBytes(int i) const
269 { 269 {
270 ASSERT((i >= 0) && i < 3); 270 ASSERT((i >= 0) && i < 3);
271 return m_rowBytes[i]; 271 return m_rowBytes[i];
272 } 272 }
273 273
274 } // namespace blink 274 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698