Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Unified Diff: third_party/WebKit/Source/core/html/ImageDataTest.cpp

Issue 2763613003: Fix signed integer overflow in ImageData (Closed)
Patch Set: Addressing comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/ImageData.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/ImageDataTest.cpp
diff --git a/third_party/WebKit/Source/core/html/ImageDataTest.cpp b/third_party/WebKit/Source/core/html/ImageDataTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..daa0d9af1063391c41fb3d93ed69c4188ff8f252
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/ImageDataTest.cpp
@@ -0,0 +1,54 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/html/ImageData.h"
+
+#include "core/dom/ExceptionCode.h"
+#include "platform/geometry/IntSize.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+namespace {
+
+class ImageDataTest : public ::testing::Test {
+ protected:
+ ImageDataTest(){};
+ void TearDown(){};
+};
+
+TEST_F(ImageDataTest, NegativeAndZeroIntSizeTest) {
+ ImageData* imageData;
+
+ imageData = ImageData::create(IntSize(0, 10));
+ EXPECT_EQ(imageData, nullptr);
+
+ imageData = ImageData::create(IntSize(10, 0));
+ EXPECT_EQ(imageData, nullptr);
+
+ imageData = ImageData::create(IntSize(0, 0));
+ EXPECT_EQ(imageData, nullptr);
+
+ imageData = ImageData::create(IntSize(-1, 10));
+ EXPECT_EQ(imageData, nullptr);
+
+ imageData = ImageData::create(IntSize(10, -1));
+ EXPECT_EQ(imageData, nullptr);
+
+ imageData = ImageData::create(IntSize(-1, -1));
+ EXPECT_EQ(imageData, nullptr);
+}
+
+// This test passes if it does not crash. If the required memory is not
+// allocated to the ImageData, then an exception must raise.
+TEST_F(ImageDataTest, CreateImageDataTooBig) {
+ DummyExceptionStateForTesting exceptionState;
+ ImageData* tooBigImageData = ImageData::create(32767, 32767, exceptionState);
+ if (!tooBigImageData) {
+ EXPECT_TRUE(exceptionState.hadException());
+ EXPECT_EQ(exceptionState.code(), V8RangeError);
+ }
+}
+
+} // namspace
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/html/ImageData.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698