aboutsummaryrefslogtreecommitdiffhomepage
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
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>
-rw-r--r--include/core/SkImageInfo.h8
-rw-r--r--include/core/SkTypes.h1
-rw-r--r--public.bzl1
-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
-rw-r--r--src/image/SkImage.cpp2
-rw-r--r--src/image/SkImage_Raster.cpp2
9 files changed, 19 insertions, 8 deletions
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index 50d068a09c..cab84b9fe0 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -317,11 +317,19 @@ public:
}
#endif
+#ifdef SK_SUPPORT_LEGACY_COMPUTEBYTESIZE_RET_0
/**
* Returns the size (in bytes) of the image buffer that this info needs, given the specified
* rowBytes. The rowBytes must be >= this->minRowBytes().
* If the calculation overflows, or if the height is 0, this returns 0.
*/
+#else
+ /**
+ * Returns the size (in bytes) of the image buffer that this info needs, given the specified
+ * rowBytes. The rowBytes must be >= this->minRowBytes().
+ * If the calculation overflows this returns SK_MaxSizeT
+ */
+#endif
size_t computeByteSize(size_t rowBytes) const;
/**
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index 63a2b40591..59bdaaa90c 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -233,6 +233,7 @@ template <typename D, typename S> D SkTo(S s) {
#define SK_MaxU32 0xFFFFFFFF
#define SK_MinU32 0
#define SK_NaN32 ((int) (1U << 31))
+#define SK_MaxSizeT SIZE_MAX
static inline int32_t SkLeftShift(int32_t value, int32_t shift) {
return (int32_t) ((uint32_t) value << shift);
diff --git a/public.bzl b/public.bzl
index e8325500a0..dfb64707d6 100644
--- a/public.bzl
+++ b/public.bzl
@@ -656,6 +656,7 @@ DEFINES_ALL = [
# Required for building dm.
"GR_TEST_UTILS",
# Staging flags for API changes
+ "SK_SUPPORT_LEGACY_COMPUTEBYTESIZE_RET_0",
# Should remove after we update golden images
"SK_WEBP_ENCODER_USE_DEFAULT_METHOD",
# Experiment to diagnose image diffs in Google3
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;
}
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 705efaec30..c67b6e4cdb 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -423,7 +423,7 @@ sk_sp<SkImage> SkImageMakeRasterCopyAndAssignColorSpace(const SkImage* src,
size_t rowBytes = info.minRowBytes();
size_t size = info.computeByteSize(rowBytes);
- if (size == 0) {
+ if (size == SK_MaxSizeT) {
return nullptr;
}
auto data = SkData::MakeUninitialized(size);
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index c576d9d3a1..e43d2c48b7 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -62,7 +62,7 @@ public:
}
size_t size = info.computeByteSize(rowBytes);
- if (0 == size) {
+ if (SK_MaxSizeT == size) {
return false;
}