Ensure that we create a NULL codec for images with zero dimensions
BUG=skia:3534
BUG=skia:3257
Review URL: https://codereview.chromium.org/1091043003
diff --git a/resources/empty_images/zero-dims.gif b/resources/empty_images/zero-dims.gif
new file mode 100644
index 0000000..8b1b084
--- /dev/null
+++ b/resources/empty_images/zero-dims.gif
Binary files differ
diff --git a/resources/empty_images/zero-embedded.ico b/resources/empty_images/zero-embedded.ico
new file mode 100644
index 0000000..d6ba292
--- /dev/null
+++ b/resources/empty_images/zero-embedded.ico
Binary files differ
diff --git a/resources/empty_images/zero-height.bmp b/resources/empty_images/zero-height.bmp
new file mode 100644
index 0000000..b07834b
--- /dev/null
+++ b/resources/empty_images/zero-height.bmp
Binary files differ
diff --git a/resources/empty_images/zero-height.jpg b/resources/empty_images/zero-height.jpg
new file mode 100644
index 0000000..14231b4
--- /dev/null
+++ b/resources/empty_images/zero-height.jpg
Binary files differ
diff --git a/resources/empty_images/zero-height.png b/resources/empty_images/zero-height.png
new file mode 100644
index 0000000..7eae117
--- /dev/null
+++ b/resources/empty_images/zero-height.png
Binary files differ
diff --git a/resources/empty_images/zero-height.wbmp b/resources/empty_images/zero-height.wbmp
new file mode 100644
index 0000000..1748771
--- /dev/null
+++ b/resources/empty_images/zero-height.wbmp
Binary files differ
diff --git a/resources/empty_images/zero-width.bmp b/resources/empty_images/zero-width.bmp
new file mode 100644
index 0000000..2e8cb8a
--- /dev/null
+++ b/resources/empty_images/zero-width.bmp
Binary files differ
diff --git a/resources/empty_images/zero-width.jpg b/resources/empty_images/zero-width.jpg
new file mode 100644
index 0000000..d1dd997
--- /dev/null
+++ b/resources/empty_images/zero-width.jpg
Binary files differ
diff --git a/resources/empty_images/zero-width.png b/resources/empty_images/zero-width.png
new file mode 100644
index 0000000..30c12fe
--- /dev/null
+++ b/resources/empty_images/zero-width.png
Binary files differ
diff --git a/resources/empty_images/zero-width.wbmp b/resources/empty_images/zero-width.wbmp
new file mode 100644
index 0000000..0a6a675
--- /dev/null
+++ b/resources/empty_images/zero-width.wbmp
Binary files differ
diff --git a/src/codec/SkCodec_libbmp.cpp b/src/codec/SkCodec_libbmp.cpp
index 56663f8..7586217 100644
--- a/src/codec/SkCodec_libbmp.cpp
+++ b/src/codec/SkCodec_libbmp.cpp
@@ -319,9 +319,9 @@
if (isIco) {
height /= 2;
}
- static const int kBmpMaxDim = 1 << 16;
- if (width < 0 || width >= kBmpMaxDim || height >= kBmpMaxDim) {
- // TODO: Decide if we want to support really large bmps.
+ if (width <= 0 || height <= 0) {
+ // TODO: Decide if we want to disable really large bmps as well.
+ // https://code.google.com/p/skia/issues/detail?id=3617
SkCodecPrintf("Error: invalid bitmap dimensions.\n");
return false;
}
diff --git a/tests/CodexTest.cpp b/tests/CodexTest.cpp
index d714251..b33e0be 100644
--- a/tests/CodexTest.cpp
+++ b/tests/CodexTest.cpp
@@ -196,5 +196,26 @@
test_dimensions(r, "randPixels.jpg");
}
+static void test_empty(skiatest::Reporter* r, const char path[]) {
+ SkAutoTDelete<SkStream> stream(resource(path));
+ if (!stream) {
+ SkDebugf("Missing resource '%s'\n", path);
+ return;
+ }
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
+ REPORTER_ASSERT(r, NULL == codec);
+}
-
+DEF_TEST(Codec_Empty, r) {
+ // Test images that should not be able to create a codec
+ test_empty(r, "empty_images/zero-dims.gif");
+ test_empty(r, "empty_images/zero-embedded.ico");
+ test_empty(r, "empty_images/zero-width.bmp");
+ test_empty(r, "empty_images/zero-height.bmp");
+ test_empty(r, "empty_images/zero-width.jpg");
+ test_empty(r, "empty_images/zero-height.jpg");
+ test_empty(r, "empty_images/zero-width.png");
+ test_empty(r, "empty_images/zero-height.png");
+ test_empty(r, "empty_images/zero-width.wbmp");
+ test_empty(r, "empty_images/zero-height.wbmp");
+}