summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Valerie Hau <vhau@google.com> 2019-07-26 14:41:43 -0700
committer Valerie Hau <vhau@google.com> 2019-08-05 09:36:54 -0700
commit3649106e95f8fe5a733b5113ba76d7a3f4a0b85c (patch)
tree0dc2f373426cfba9b140acb56254bc292cc2a31c
parent6c37f41007ecd66fd09e0428b6c0136854aabf6c (diff)
Adding test to test closer boundary for overflow
Bug: 137801859 Test: build, boot, GraphicBuffer_test Change-Id: Ic5c74a52dcf325c9151f63bd9bbb11ea17222b0b
-rw-r--r--libs/ui/tests/GraphicBuffer_test.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/libs/ui/tests/GraphicBuffer_test.cpp b/libs/ui/tests/GraphicBuffer_test.cpp
index 127f7eedd6..5e0b094b7b 100644
--- a/libs/ui/tests/GraphicBuffer_test.cpp
+++ b/libs/ui/tests/GraphicBuffer_test.cpp
@@ -44,11 +44,28 @@ TEST_F(GraphicBufferTest, AllocateNoError) {
TEST_F(GraphicBufferTest, AllocateBadDimensions) {
PixelFormat format = PIXEL_FORMAT_RGBA_8888;
+ if (std::numeric_limits<size_t>::max() / std::numeric_limits<uint32_t>::max() /
+ bytesPerPixel(format) >=
+ std::numeric_limits<uint32_t>::max()) {
+ GTEST_SUCCEED() << "Cannot overflow with this format";
+ }
uint32_t width, height;
width = height = std::numeric_limits<uint32_t>::max();
sp<GraphicBuffer> gb(new GraphicBuffer(width, height, format, kTestLayerCount, kTestUsage,
std::string("test")));
ASSERT_EQ(BAD_VALUE, gb->initCheck());
+
+ const size_t targetArea = std::numeric_limits<size_t>::max() / bytesPerPixel(format);
+ const size_t widthCandidate = targetArea / std::numeric_limits<uint32_t>::max();
+ if (widthCandidate == 0) {
+ width = 1;
+ } else {
+ width = std::numeric_limits<uint32_t>::max();
+ }
+ height = (targetArea / width) + 1;
+ sp<GraphicBuffer> gb2(new GraphicBuffer(width, height, format, kTestLayerCount, kTestUsage,
+ std::string("test")));
+ ASSERT_EQ(BAD_VALUE, gb2->initCheck());
}
TEST_F(GraphicBufferTest, CreateFromBufferHubBuffer) {