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

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

Issue 376803004: Adding validation before using an SkImageInfo object read from an SkReadBuffer. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Added missing check before computing minRowBytes() Created 6 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
« 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 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 1194
1195 bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) { 1195 bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) {
1196 const size_t snugRB = buffer->readUInt(); 1196 const size_t snugRB = buffer->readUInt();
1197 if (0 == snugRB) { // no pixels 1197 if (0 == snugRB) { // no pixels
1198 return false; 1198 return false;
1199 } 1199 }
1200 1200
1201 SkImageInfo info; 1201 SkImageInfo info;
1202 info.unflatten(*buffer); 1202 info.unflatten(*buffer);
1203 1203
1204 // If there was an error reading "info", don't use it to compute minRowBytes ()
1205 if (!buffer->validate(true)) {
1206 return false;
1207 }
1208
1204 const size_t ramRB = info.minRowBytes(); 1209 const size_t ramRB = info.minRowBytes();
1205 const int height = info.height(); 1210 const int height = info.height();
1206 const size_t snugSize = snugRB * height; 1211 const size_t snugSize = snugRB * height;
1207 const size_t ramSize = ramRB * height; 1212 const size_t ramSize = ramRB * height;
1208 if (!buffer->validate(snugSize <= ramSize)) { 1213 if (!buffer->validate(snugSize <= ramSize)) {
1209 return false; 1214 return false;
1210 } 1215 }
1211 1216
1212 char* dst = (char*)sk_malloc_throw(ramSize); 1217 char* dst = (char*)sk_malloc_throw(ramSize);
1213 buffer->readByteArray(dst, snugSize); 1218 buffer->readByteArray(dst, snugSize);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 /////////////////////////////////////////////////////////////////////////////// 1383 ///////////////////////////////////////////////////////////////////////////////
1379 1384
1380 #ifdef SK_DEBUG 1385 #ifdef SK_DEBUG
1381 void SkImageInfo::validate() const { 1386 void SkImageInfo::validate() const {
1382 SkASSERT(fWidth >= 0); 1387 SkASSERT(fWidth >= 0);
1383 SkASSERT(fHeight >= 0); 1388 SkASSERT(fHeight >= 0);
1384 SkASSERT(SkColorTypeIsValid(fColorType)); 1389 SkASSERT(SkColorTypeIsValid(fColorType));
1385 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); 1390 SkASSERT(SkAlphaTypeIsValid(fAlphaType));
1386 } 1391 }
1387 #endif 1392 #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