Revert "change computeByteSize to return max_size_t on overflow"
This reverts commit 2429546272
.
Reason for revert: broke running dm on google3
Original change's description:
> 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>
TBR=bungeman@google.com,herb@google.com,reed@google.com
Change-Id: I5f58ec37241d2fae3ebdb7a3d6b41f9fd6d3c2ee
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:7132
Reviewed-on: https://skia-review.googlesource.com/56880
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
e1da1d9a7d
commit
384f0a7d66
@ -317,19 +317,11 @@ 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;
|
||||
|
||||
/**
|
||||
|
@ -233,7 +233,6 @@ 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);
|
||||
|
@ -656,7 +656,6 @@ 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
|
||||
|
@ -37,7 +37,7 @@ bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) {
|
||||
|
||||
size_t rb;
|
||||
size_t size = AllocSize(info, &rb);
|
||||
if (SK_MaxSizeT == size) {
|
||||
if (0 == size) {
|
||||
return false;
|
||||
}
|
||||
void* pixels = sk_malloc_flags(size, 0);
|
||||
|
@ -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 (SK_MaxSizeT == size) {
|
||||
if (0 == size) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -78,11 +78,7 @@ 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) {
|
||||
|
@ -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 == SK_MaxSizeT) {
|
||||
if (!size) {
|
||||
return nullptr; // overflow
|
||||
}
|
||||
}
|
||||
@ -131,6 +131,9 @@ 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;
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ sk_sp<SkImage> SkImageMakeRasterCopyAndAssignColorSpace(const SkImage* src,
|
||||
|
||||
size_t rowBytes = info.minRowBytes();
|
||||
size_t size = info.computeByteSize(rowBytes);
|
||||
if (size == SK_MaxSizeT) {
|
||||
if (size == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
auto data = SkData::MakeUninitialized(size);
|
||||
|
@ -62,7 +62,7 @@ public:
|
||||
}
|
||||
|
||||
size_t size = info.computeByteSize(rowBytes);
|
||||
if (SK_MaxSizeT == size) {
|
||||
if (0 == size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user