blob: e5b8b0531dbeeb4a9170790d1b20f1559eb94f05 [file] [log] [blame]
kumarashishg826308d2023-06-23 13:21:22 +00001// Copyright 2015 The PDFium Authors
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Haibo Huang49cc9302020-04-27 16:14:24 -07005#include "build/build_config.h"
6#include "core/fpdfapi/parser/fpdf_parser_decode.h"
Haibo Huang49cc9302020-04-27 16:14:24 -07007#include "public/cpp/fpdf_scopers.h"
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -07008#include "testing/embedder_test.h"
kumarashishg826308d2023-06-23 13:21:22 +00009#include "testing/embedder_test_constants.h"
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070010#include "testing/gtest/include/gtest/gtest.h"
11#include "testing/test_support.h"
12
Haibo Huang49cc9302020-04-27 16:14:24 -070013using FPDFParserDecodeEmbedderTest = EmbedderTest;
kumarashishg826308d2023-06-23 13:21:22 +000014using pdfium::kBlankPage612By792Checksum;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070015
kumarashishg826308d2023-06-23 13:21:22 +000016TEST_F(FPDFParserDecodeEmbedderTest, Bug552046) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070017 // Tests specifying multiple image filters for a stream. Should not cause a
18 // crash when rendered.
kumarashishg826308d2023-06-23 13:21:22 +000019 ASSERT_TRUE(OpenDocument("bug_552046.pdf"));
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070020 FPDF_PAGE page = LoadPage(0);
Haibo Huang49cc9302020-04-27 16:14:24 -070021 ASSERT_TRUE(page);
22 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
kumarashishg826308d2023-06-23 13:21:22 +000023 CompareBitmap(bitmap.get(), 612, 792, kBlankPage612By792Checksum);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070024 UnloadPage(page);
25}
26
kumarashishg826308d2023-06-23 13:21:22 +000027TEST_F(FPDFParserDecodeEmbedderTest, Bug555784) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070028 // Tests bad input to the run length decoder that caused a heap overflow.
29 // Should not cause a crash when rendered.
kumarashishg826308d2023-06-23 13:21:22 +000030 ASSERT_TRUE(OpenDocument("bug_555784.pdf"));
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070031 FPDF_PAGE page = LoadPage(0);
Haibo Huang49cc9302020-04-27 16:14:24 -070032 ASSERT_TRUE(page);
33 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
kumarashishg826308d2023-06-23 13:21:22 +000034 CompareBitmap(bitmap.get(), 612, 792, kBlankPage612By792Checksum);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070035 UnloadPage(page);
36}
37
kumarashishg826308d2023-06-23 13:21:22 +000038TEST_F(FPDFParserDecodeEmbedderTest, Bug455199) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070039 // Tests object numbers with a value > 01000000.
40 // Should open successfully.
kumarashishg826308d2023-06-23 13:21:22 +000041 ASSERT_TRUE(OpenDocument("bug_455199.pdf"));
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070042 FPDF_PAGE page = LoadPage(0);
Haibo Huang49cc9302020-04-27 16:14:24 -070043 ASSERT_TRUE(page);
44 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
kumarashishg826308d2023-06-23 13:21:22 +000045
46 CompareBitmap(bitmap.get(), 200, 200, pdfium::HelloWorldChecksum());
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070047 UnloadPage(page);
48}