aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-10-06 15:04:23 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-06 19:36:17 +0000
commit24295462722fd5a298d108a80b0aacbb0964da53 (patch)
treed98efb1e32f860294629ddb154199382136b60c1 /src/core
parent9cb2cae63584d0bfb8c98a90062d06ff59659e72 (diff)
change computeByteSize to return max_size_t on overflow
Bug: skia:7132 Change-Id: I41045640ee62b2c988a84370ead5034bbccc6daf Reviewed-on: https://skia-review.googlesource.com/56620 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkAutoPixmapStorage.cpp2
-rw-r--r--src/core/SkBitmapCache.cpp2
-rw-r--r--src/core/SkImageInfo.cpp4
-rw-r--r--src/core/SkMallocPixelRef.cpp5
4 files changed, 7 insertions, 6 deletions
diff --git a/src/core/SkAutoPixmapStorage.cpp b/src/core/SkAutoPixmapStorage.cpp
index df0c0fa878..fb8ad00246 100644
--- a/src/core/SkAutoPixmapStorage.cpp
+++ b/src/core/SkAutoPixmapStorage.cpp
@@ -37,7 +37,7 @@ bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) {
size_t rb;
size_t size = AllocSize(info, &rb);
- if (0 == size) {
+ if (SK_MaxSizeT == size) {
return false;
}
void* pixels = sk_malloc_flags(size, 0);
diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp
index 8d3991a9d5..2f163183db 100644
--- a/src/core/SkBitmapCache.cpp
+++ b/src/core/SkBitmapCache.cpp
@@ -290,7 +290,7 @@ SkBitmapCache::RecPtr SkBitmapCache::Alloc(const SkBitmapCacheDesc& desc, const
const size_t rb = info.minRowBytes();
size_t size = info.computeByteSize(rb);
- if (0 == size) {
+ if (SK_MaxSizeT == size) {
return nullptr;
}
diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp
index c610b82bdc..9e08768d7b 100644
--- a/src/core/SkImageInfo.cpp
+++ b/src/core/SkImageInfo.cpp
@@ -78,7 +78,11 @@ size_t SkImageInfo::computeByteSize(size_t rowBytes) const {
SkSafeMath safe;
size_t bytes = safe.add(safe.mul(fHeight - 1, rowBytes),
safe.mul(fWidth, this->bytesPerPixel()));
+#ifdef SK_SUPPORT_LEGACY_COMPUTEBYTESIZE_RET_0
return safe ? bytes : 0;
+#else
+ return safe ? bytes : SK_MaxSizeT;
+#endif
}
static bool alpha_type_is_valid(SkAlphaType alphaType) {
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp
index 10861028b1..531d9f8fdf 100644
--- a/src/core/SkMallocPixelRef.cpp
+++ b/src/core/SkMallocPixelRef.cpp
@@ -80,7 +80,7 @@ sk_sp<SkPixelRef> SkMallocPixelRef::MakeUsing(void*(*allocProc)(size_t),
size_t size = 0;
if (!info.isEmpty() && rowBytes) {
size = info.computeByteSize(rowBytes);
- if (!size) {
+ if (size == SK_MaxSizeT) {
return nullptr; // overflow
}
}
@@ -131,9 +131,6 @@ sk_sp<SkPixelRef> SkMallocPixelRef::MakeWithData(const SkImageInfo& info,
if (!is_valid(info)) {
return nullptr;
}
- // TODO: what should we return if computeByteSize returns 0?
- // - the info was empty?
- // - we overflowed computing the size?
if ((rowBytes < info.minRowBytes()) || (data->size() < info.computeByteSize(rowBytes))) {
return nullptr;
}