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

Side by Side Diff: src/core/SkBitmap.cpp

Issue 836733005: Verify size_t overflow (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Used SkToSizeT Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2008 The Android Open Source Project 3 * Copyright 2008 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 1195
1196 SkImageInfo info; 1196 SkImageInfo info;
1197 info.unflatten(*buffer); 1197 info.unflatten(*buffer);
1198 1198
1199 // If there was an error reading "info", don't use it to compute minRowBytes () 1199 // If there was an error reading "info", don't use it to compute minRowBytes ()
1200 if (!buffer->validate(true)) { 1200 if (!buffer->validate(true)) {
1201 return false; 1201 return false;
1202 } 1202 }
1203 1203
1204 const size_t ramRB = info.minRowBytes(); 1204 const size_t ramRB = info.minRowBytes();
1205 const int height = info.height(); 1205 const int height = SkMax32(info.height(), 0);
1206 const size_t snugSize = snugRB * height; 1206 const uint64_t snugSize = sk_64_mul(snugRB, height);
1207 const size_t ramSize = ramRB * height; 1207 const uint64_t ramSize = sk_64_mul(ramRB, height);
1208 if (!buffer->validate(snugSize <= ramSize)) { 1208 static const uint64_t max_size_t = (size_t)(-1);
1209 if (!buffer->validate((snugSize <= ramSize) && (ramSize <= max_size_t))) {
Stephen White 2015/01/07 19:22:29 static const uint64_t max_size_t = (size_t)(-1); i
1209 return false; 1210 return false;
1210 } 1211 }
1211 1212
1212 SkAutoDataUnref data(SkData::NewUninitialized(ramSize)); 1213 SkAutoDataUnref data(SkData::NewUninitialized(SkToSizeT(ramSize)));
1213 char* dst = (char*)data->writable_data(); 1214 char* dst = (char*)data->writable_data();
1214 buffer->readByteArray(dst, snugSize); 1215 buffer->readByteArray(dst, SkToSizeT(snugSize));
1215 1216
1216 if (snugSize != ramSize) { 1217 if (snugSize != ramSize) {
1217 const char* srcRow = dst + snugRB * (height - 1); 1218 const char* srcRow = dst + snugRB * (height - 1);
1218 char* dstRow = dst + ramRB * (height - 1); 1219 char* dstRow = dst + ramRB * (height - 1);
1219 for (int y = height - 1; y >= 1; --y) { 1220 for (int y = height - 1; y >= 1; --y) {
1220 memmove(dstRow, srcRow, snugRB); 1221 memmove(dstRow, srcRow, snugRB);
1221 srcRow -= snugRB; 1222 srcRow -= snugRB;
1222 dstRow -= ramRB; 1223 dstRow -= ramRB;
1223 } 1224 }
1224 SkASSERT(srcRow == dstRow); // first row does not need to be moved 1225 SkASSERT(srcRow == dstRow); // first row does not need to be moved
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 /////////////////////////////////////////////////////////////////////////////// 1379 ///////////////////////////////////////////////////////////////////////////////
1379 1380
1380 #ifdef SK_DEBUG 1381 #ifdef SK_DEBUG
1381 void SkImageInfo::validate() const { 1382 void SkImageInfo::validate() const {
1382 SkASSERT(fWidth >= 0); 1383 SkASSERT(fWidth >= 0);
1383 SkASSERT(fHeight >= 0); 1384 SkASSERT(fHeight >= 0);
1384 SkASSERT(SkColorTypeIsValid(fColorType)); 1385 SkASSERT(SkColorTypeIsValid(fColorType));
1385 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); 1386 SkASSERT(SkAlphaTypeIsValid(fAlphaType));
1386 } 1387 }
1387 #endif 1388 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698