Ensure that we create a NULL codec for images with zero dimensions
authormsarett <msarett@google.com>
Thu, 23 Apr 2015 15:53:39 +0000 (08:53 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 23 Apr 2015 15:53:39 +0000 (08:53 -0700)
BUG=skia:3534
BUG=skia:3257

Review URL: https://codereview.chromium.org/1091043003

12 files changed:
resources/empty_images/zero-dims.gif [new file with mode: 0644]
resources/empty_images/zero-embedded.ico [new file with mode: 0644]
resources/empty_images/zero-height.bmp [new file with mode: 0644]
resources/empty_images/zero-height.jpg [new file with mode: 0644]
resources/empty_images/zero-height.png [new file with mode: 0644]
resources/empty_images/zero-height.wbmp [new file with mode: 0644]
resources/empty_images/zero-width.bmp [new file with mode: 0644]
resources/empty_images/zero-width.jpg [new file with mode: 0644]
resources/empty_images/zero-width.png [new file with mode: 0644]
resources/empty_images/zero-width.wbmp [new file with mode: 0644]
src/codec/SkCodec_libbmp.cpp
tests/CodexTest.cpp

diff --git a/resources/empty_images/zero-dims.gif b/resources/empty_images/zero-dims.gif
new file mode 100644 (file)
index 0000000..8b1b084
Binary files /dev/null and b/resources/empty_images/zero-dims.gif differ
diff --git a/resources/empty_images/zero-embedded.ico b/resources/empty_images/zero-embedded.ico
new file mode 100644 (file)
index 0000000..d6ba292
Binary files /dev/null and b/resources/empty_images/zero-embedded.ico differ
diff --git a/resources/empty_images/zero-height.bmp b/resources/empty_images/zero-height.bmp
new file mode 100644 (file)
index 0000000..b07834b
Binary files /dev/null and b/resources/empty_images/zero-height.bmp differ
diff --git a/resources/empty_images/zero-height.jpg b/resources/empty_images/zero-height.jpg
new file mode 100644 (file)
index 0000000..14231b4
Binary files /dev/null and b/resources/empty_images/zero-height.jpg differ
diff --git a/resources/empty_images/zero-height.png b/resources/empty_images/zero-height.png
new file mode 100644 (file)
index 0000000..7eae117
Binary files /dev/null and b/resources/empty_images/zero-height.png differ
diff --git a/resources/empty_images/zero-height.wbmp b/resources/empty_images/zero-height.wbmp
new file mode 100644 (file)
index 0000000..1748771
Binary files /dev/null and b/resources/empty_images/zero-height.wbmp differ
diff --git a/resources/empty_images/zero-width.bmp b/resources/empty_images/zero-width.bmp
new file mode 100644 (file)
index 0000000..2e8cb8a
Binary files /dev/null and b/resources/empty_images/zero-width.bmp differ
diff --git a/resources/empty_images/zero-width.jpg b/resources/empty_images/zero-width.jpg
new file mode 100644 (file)
index 0000000..d1dd997
Binary files /dev/null and b/resources/empty_images/zero-width.jpg differ
diff --git a/resources/empty_images/zero-width.png b/resources/empty_images/zero-width.png
new file mode 100644 (file)
index 0000000..30c12fe
Binary files /dev/null and b/resources/empty_images/zero-width.png differ
diff --git a/resources/empty_images/zero-width.wbmp b/resources/empty_images/zero-width.wbmp
new file mode 100644 (file)
index 0000000..0a6a675
Binary files /dev/null and b/resources/empty_images/zero-width.wbmp differ
index 56663f8..7586217 100644 (file)
@@ -319,9 +319,9 @@ bool SkBmpCodec::ReadHeader(SkStream* stream, bool isIco, SkCodec** codecOut) {
     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;
     }
index d714251..b33e0be 100644 (file)
@@ -196,5 +196,26 @@ DEF_TEST(Codec_Dimensions, r) {
     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");
+}