OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 |
OLD | NEW |