aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2014-12-31 12:31:43 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-12-31 12:31:43 -0800
commitb2497c2d945c0a5d770865b026e2d5947bf37c91 (patch)
tree1f9e748eb4e0ece2253dfe6ae6120f0d90252cbb /src
parent55374058b3d3c477867c3dcb19269272d5d2bbc7 (diff)
change API contract: disallow zero-sized images or surfaces
Diffstat (limited to 'src')
-rw-r--r--src/image/SkImage_Raster.cpp32
-rw-r--r--src/image/SkSurface.cpp8
-rw-r--r--src/image/SkSurface_Raster.cpp4
-rw-r--r--src/lazy/SkDiscardablePixelRef.cpp1
4 files changed, 12 insertions, 33 deletions
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index a06cca6e9b..0ee391464f 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -19,7 +19,7 @@ public:
const int maxDimension = SK_MaxS32 >> 2;
const size_t kMaxPixelByteSize = SK_MaxS32;
- if (info.width() < 0 || info.height() < 0) {
+ if (info.width() <= 0 || info.height() <= 0) {
return false;
}
if (info.width() > maxDimension || info.height() > maxDimension) {
@@ -49,8 +49,6 @@ public:
return true;
}
- static SkImage* NewEmpty();
-
SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, const SkSurfaceProps*);
virtual ~SkImage_Raster();
@@ -86,16 +84,6 @@ private:
///////////////////////////////////////////////////////////////////////////////
-SkImage* SkImage_Raster::NewEmpty() {
- // Returns lazily created singleton
- static SkImage* gEmpty;
- if (NULL == gEmpty) {
- gEmpty = SkNEW(SkImage_Raster);
- }
- gEmpty->ref();
- return gEmpty;
-}
-
static void release_data(void* addr, void* context) {
SkData* data = static_cast<SkData*>(context);
data->unref();
@@ -169,14 +157,7 @@ bool SkImage_Raster::getROPixels(SkBitmap* dst) const {
///////////////////////////////////////////////////////////////////////////////
SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, size_t rowBytes) {
- if (!SkImage_Raster::ValidArgs(info, rowBytes)) {
- return NULL;
- }
- if (0 == info.width() && 0 == info.height()) {
- return SkImage_Raster::NewEmpty();
- }
- // check this after empty-check
- if (NULL == pixels) {
+ if (!SkImage_Raster::ValidArgs(info, rowBytes) || !pixels) {
return NULL;
}
@@ -187,14 +168,7 @@ SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz
SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t rowBytes) {
- if (!SkImage_Raster::ValidArgs(info, rowBytes)) {
- return NULL;
- }
- if (0 == info.width() && 0 == info.height()) {
- return SkImage_Raster::NewEmpty();
- }
- // check this after empty-check
- if (NULL == data) {
+ if (!SkImage_Raster::ValidArgs(info, rowBytes) || !data) {
return NULL;
}
diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp
index dca4ce771c..6fd40c10af 100644
--- a/src/image/SkSurface.cpp
+++ b/src/image/SkSurface.cpp
@@ -123,16 +123,16 @@ static SkSurface_Base* asSB(SkSurface* surface) {
SkSurface::SkSurface(int width, int height, const SkSurfaceProps* props)
: fProps(SkSurfacePropsCopyOrDefault(props)), fWidth(width), fHeight(height)
{
- SkASSERT(fWidth >= 0);
- SkASSERT(fHeight >= 0);
+ SkASSERT(fWidth > 0);
+ SkASSERT(fHeight > 0);
fGenerationID = 0;
}
SkSurface::SkSurface(const SkImageInfo& info, const SkSurfaceProps* props)
: fProps(SkSurfacePropsCopyOrDefault(props)), fWidth(info.width()), fHeight(info.height())
{
- SkASSERT(fWidth >= 0);
- SkASSERT(fHeight >= 0);
+ SkASSERT(fWidth > 0);
+ SkASSERT(fHeight > 0);
fGenerationID = 0;
}
diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp
index b221c130e5..2bac3f3156 100644
--- a/src/image/SkSurface_Raster.cpp
+++ b/src/image/SkSurface_Raster.cpp
@@ -39,6 +39,10 @@ private:
///////////////////////////////////////////////////////////////////////////////
bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) {
+ if (info.isEmpty()) {
+ return false;
+ }
+
static const size_t kMaxTotalSize = SK_MaxS32;
int shift = 0;
diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp
index c4e3654d1a..84152ed188 100644
--- a/src/lazy/SkDiscardablePixelRef.cpp
+++ b/src/lazy/SkDiscardablePixelRef.cpp
@@ -98,6 +98,7 @@ bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst,
SkAutoTDelete<SkImageGenerator> autoGenerator(generator);
if ((NULL == autoGenerator.get())
|| (!autoGenerator->getInfo(&info))
+ || info.isEmpty()
|| (!dst->setInfo(info))) {
return false;
}