Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b298f43c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Adding test to test closer boundary for overflow"

parents 8fcb80bc 3649106e
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -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) {