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

Unified Diff: core/fxcodec/jbig2/JBig2_Image_unittest.cpp

Issue 2202013002: Bound total pixels in JBig2 images to avoid overflows later. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Add tests Created 4 years, 4 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 | « core/fxcodec/jbig2/JBig2_Image.cpp ('k') | core/fxcodec/jbig2/JBig2_SddProc.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcodec/jbig2/JBig2_Image_unittest.cpp
diff --git a/core/fxcodec/jbig2/JBig2_Image_unittest.cpp b/core/fxcodec/jbig2/JBig2_Image_unittest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..788f922a02e97280cd0669e482544b139241c67a
--- /dev/null
+++ b/core/fxcodec/jbig2/JBig2_Image_unittest.cpp
@@ -0,0 +1,105 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// TODO(tsepez) this requires a lot more testing.
+
+#include <stdint.h>
+
+#include "core/fxcodec/jbig2/JBig2_Image.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const int32_t kWidthPixels = 80;
+const int32_t kWidthBytes = 10;
+const int32_t kStrideBytes = kWidthBytes + 1; // For testing stride != width.
+const int32_t kHeightLines = 20;
+const int32_t kLargerHeightLines = 100;
+const int32_t kTooLargeHeightLines = 40000000;
+
+} // namespace
+
+TEST(fxcodec, JBig2ImageCreate) {
+ CJBig2_Image img(kWidthPixels, kHeightLines);
+ img.setPixel(0, 0, true);
+ img.setPixel(kWidthPixels - 1, kHeightLines - 1, false);
+ EXPECT_EQ(kWidthPixels, img.width());
+ EXPECT_EQ(kHeightLines, img.height());
+ EXPECT_TRUE(img.getPixel(0, 0));
+ EXPECT_FALSE(img.getPixel(kWidthPixels - 1, kHeightLines - 1));
+}
+
+TEST(fxcodec, JBig2ImageCreateTooBig) {
+ CJBig2_Image img(kWidthPixels, kTooLargeHeightLines);
+ EXPECT_EQ(0, img.width());
+ EXPECT_EQ(0, img.height());
+ EXPECT_EQ(nullptr, img.m_pData);
Lei Zhang 2016/08/02 19:36:56 You can also do EXPECT_FALSE(ptr);
+}
+
+TEST(fxcodec, JBig2ImageCreateExternal) {
+ uint8_t buf[kHeightLines * kStrideBytes];
+ CJBig2_Image img(kWidthPixels, kHeightLines, kStrideBytes, buf);
+ img.setPixel(0, 0, true);
+ img.setPixel(kWidthPixels - 1, kHeightLines - 1, false);
+ EXPECT_EQ(kWidthPixels, img.width());
+ EXPECT_EQ(kHeightLines, img.height());
+ EXPECT_TRUE(img.getPixel(0, 0));
+ EXPECT_FALSE(img.getPixel(kWidthPixels - 1, kHeightLines - 1));
+}
+
+TEST(fxcodec, JBig2ImageCreateExternalTooBig) {
+ uint8_t buf[kHeightLines * kStrideBytes];
+ CJBig2_Image img(kWidthPixels, kTooLargeHeightLines, kStrideBytes, buf);
+ EXPECT_EQ(0, img.width());
+ EXPECT_EQ(0, img.height());
+ EXPECT_EQ(nullptr, img.m_pData);
+}
+
+TEST(fxcodec, JBig2ImageExpand) {
+ CJBig2_Image img(kWidthPixels, kHeightLines);
+ img.setPixel(0, 0, true);
+ img.setPixel(kWidthPixels - 1, kHeightLines - 1, false);
+ img.expand(kLargerHeightLines, true);
+ EXPECT_EQ(kWidthPixels, img.width());
+ EXPECT_EQ(kLargerHeightLines, img.height());
+ EXPECT_TRUE(img.getPixel(0, 0));
+ EXPECT_FALSE(img.getPixel(kWidthPixels - 1, kHeightLines - 1));
+ EXPECT_TRUE(img.getPixel(kWidthPixels - 1, kLargerHeightLines - 1));
+}
+
+TEST(fxcodec, JBig2ImageExpandTooBig) {
+ CJBig2_Image img(kWidthPixels, kHeightLines);
+ img.setPixel(0, 0, true);
+ img.setPixel(kWidthPixels - 1, kHeightLines - 1, false);
+ img.expand(kTooLargeHeightLines, true);
+ EXPECT_EQ(kWidthPixels, img.width());
+ EXPECT_EQ(kHeightLines, img.height());
+ EXPECT_TRUE(img.getPixel(0, 0));
+ EXPECT_FALSE(img.getPixel(kWidthPixels - 1, kHeightLines - 1));
+}
+
+TEST(fxcodec, JBig2ImageExpandExternal) {
+ uint8_t buf[kHeightLines * kStrideBytes];
+ CJBig2_Image img(kWidthPixels, kHeightLines, kStrideBytes, buf);
+ img.setPixel(0, 0, true);
+ img.setPixel(kWidthPixels - 1, kHeightLines - 1, false);
+ img.expand(kLargerHeightLines, true);
+ EXPECT_EQ(kWidthPixels, img.width());
+ EXPECT_EQ(kLargerHeightLines, img.height());
+ EXPECT_TRUE(img.getPixel(0, 0));
+ EXPECT_FALSE(img.getPixel(kWidthPixels - 1, kHeightLines - 1));
+ EXPECT_TRUE(img.getPixel(kWidthPixels - 1, kLargerHeightLines - 1));
+}
+
+TEST(fxcodec, JBig2ImageExpandExternalTooBig) {
+ uint8_t buf[kHeightLines * kStrideBytes];
+ CJBig2_Image img(kWidthPixels, kHeightLines, kStrideBytes, buf);
+ img.setPixel(0, 0, true);
+ img.setPixel(kWidthPixels - 1, kHeightLines - 1, false);
+ img.expand(kTooLargeHeightLines, true);
+ EXPECT_EQ(kWidthPixels, img.width());
+ EXPECT_EQ(kHeightLines, img.height());
+ EXPECT_TRUE(img.getPixel(0, 0));
+ EXPECT_FALSE(img.getPixel(kWidthPixels - 1, kHeightLines - 1));
+}
« no previous file with comments | « core/fxcodec/jbig2/JBig2_Image.cpp ('k') | core/fxcodec/jbig2/JBig2_SddProc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698