| 1 |
// SPDX-FileCopyrightText: 2023 Francesco Pretto <[email protected]> |
| 2 |
// SPDX-License-Identifier: MIT-0 |
| 3 |
|
| 4 |
#include <PdfTest.h> |
| 5 |
#include <podofo/private/OpenSSLInternal.h> |
| 6 |
|
| 7 |
using namespace std; |
| 8 |
using namespace PoDoFo; |
| 9 |
|
| 10 |
TEST_CASE("TestFixInvalidCrossReferenceTable") |
| 11 |
{ |
| 12 |
PdfMemDocument doc; |
| 13 |
doc.Load(TestUtils::GetTestInputFilePath("TestFixInvalidCrossReferenceTable.pdf")); |
| 14 |
doc.Save(TestUtils::GetTestOutputFilePath("TestFixInvalidCrossReferenceTable.pdf"), PdfSaveOptions::NoMetadataUpdate); |
| 15 |
charbuff buff; |
| 16 |
utls::ReadTo(buff, TestUtils::GetTestOutputFilePath("TestFixInvalidCrossReferenceTable.pdf")); |
| 17 |
REQUIRE(ssl::ComputeMD5Str(buff) == "FF980936FDE894F4495DDEC7C13AF4F4"); |
| 18 |
} |
| 19 |
|
| 20 |
TEST_CASE("TestXRefSectionShifted") |
| 21 |
{ |
| 22 |
// The xref subsection header starts at object 1 instead of 0, shifting |
| 23 |
// every entry by one object so /Root resolves to a free entry. The catalog |
| 24 |
// validation performed while parsing fails and triggers a rebuild of the |
| 25 |
// cross reference table, after which the document loads correctly |
| 26 |
// This issue was discussed in https://github.com/podofo/podofo/issues/357 |
| 27 |
PdfMemDocument doc; |
| 28 |
doc.Load(TestUtils::GetTestInputFilePath("Corrupted", "XRefSectionShifted.pdf")); |
| 29 |
REQUIRE(doc.HasBrokenXRef()); |
| 30 |
REQUIRE(doc.GetPages().GetCount() == 1); |
| 31 |
} |
| 32 |
|
| 33 |
TEST_CASE("TestMalformedAnnotationAction") |
| 34 |
{ |
| 35 |
// Test that a PDF with a malformed action in a Link annotation does not |
| 36 |
// crash when accessing the annotation's action. |
| 37 |
PdfMemDocument doc; |
| 38 |
doc.Load(TestUtils::GetTestInputFilePath("TestMalformedAnnotationAction.pdf")); |
| 39 |
|
| 40 |
auto& page = doc.GetPages().GetPageAt(0); |
| 41 |
REQUIRE(page.GetAnnotations().GetCount() == 1); |
| 42 |
|
| 43 |
auto& annot = page.GetAnnotations().GetAnnotAt(0); |
| 44 |
REQUIRE(annot.GetType() == PdfAnnotationType::Link); |
| 45 |
|
| 46 |
auto& linkAnnot = static_cast<PdfAnnotationLink&>(annot); |
| 47 |
auto action = linkAnnot.GetAction(); |
| 48 |
REQUIRE(action == nullptr); |
| 49 |
} |