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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkBitmap.cpp
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 9db596de9cc9023fe32ae9b5ba24ae473e041345..c962aea21a10fc3dd4e31705a9c334dcf83e450d 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -1202,16 +1202,17 @@ bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) {
}
const size_t ramRB = info.minRowBytes();
- const int height = info.height();
- const size_t snugSize = snugRB * height;
- const size_t ramSize = ramRB * height;
- if (!buffer->validate(snugSize <= ramSize)) {
+ const int height = SkMax32(info.height(), 0);
+ const uint64_t snugSize = sk_64_mul(snugRB, height);
+ const uint64_t ramSize = sk_64_mul(ramRB, height);
+ static const uint64_t max_size_t = (size_t)(-1);
+ 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
return false;
}
- SkAutoDataUnref data(SkData::NewUninitialized(ramSize));
+ SkAutoDataUnref data(SkData::NewUninitialized(SkToSizeT(ramSize)));
char* dst = (char*)data->writable_data();
- buffer->readByteArray(dst, snugSize);
+ buffer->readByteArray(dst, SkToSizeT(snugSize));
if (snugSize != ramSize) {
const char* srcRow = dst + snugRB * (height - 1);
« 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