Coverage Report

Created: 2026-10-31 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xpdf-4.06/build/fuzz_pdfload.cc
Line
Count
Source
1
/*  Copyright 2020 Google Inc.
2
3
Licensed under the Apache License, Version 2.0 (the "License");
4
you may not use this file except in compliance with the License.
5
You may obtain a copy of the License at
6
7
      http://www.apache.org/licenses/LICENSE-2.0
8
9
Unless required by applicable law or agreed to in writing, software
10
distributed under the License is distributed on an "AS IS" BASIS,
11
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
See the License for the specific language governing permissions and
13
limitations under the License.
14
*/
15
#include <fuzzer/FuzzedDataProvider.h>
16
17
#include <vector>
18
#include <aconf.h>
19
#include <stdio.h>
20
#include <stdint.h>
21
#include <stdlib.h>
22
#include <stddef.h>
23
#include <string.h>
24
#include <png.h>
25
26
#include "gmem.h"
27
#include "gmempp.h"
28
#include "parseargs.h"
29
#include "GString.h"
30
#include "gfile.h"
31
#include "GlobalParams.h"
32
#include "Object.h"
33
#include "PDFDoc.h"
34
#include "SplashBitmap.h"
35
#include "Splash.h"
36
#include "SplashOutputDev.h"
37
#include "Stream.h"
38
#include "config.h"
39
#include "JBIG2Stream.h"
40
41
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
42
18.5k
{
43
18.5k
    FuzzedDataProvider fdp (data, size);
44
18.5k
    double hdpi = fdp.ConsumeFloatingPoint<double>();
45
18.5k
    double vdpi = fdp.ConsumeFloatingPoint<double>();
46
18.5k
    int rotate = fdp.ConsumeIntegral<int>();
47
18.5k
    bool useMediaBox = fdp.ConsumeBool();
48
18.5k
    bool crop = fdp.ConsumeBool();
49
18.5k
    bool printing = fdp.ConsumeBool();
50
18.5k
    std::vector<char> payload = fdp.ConsumeRemainingBytes<char>();
51
52
18.5k
    Object xpdf_obj;
53
18.5k
    xpdf_obj.initNull();
54
18.5k
    BaseStream *stream = new MemStream(payload.data(), 0, payload.size(), &xpdf_obj);
55
56
18.5k
    Object info, xfa;
57
18.5k
    Object *acroForm;
58
18.5k
    globalParams = new GlobalParams(NULL);
59
18.5k
    globalParams->setErrQuiet(1);
60
18.5k
    globalParams->setupBaseFonts(NULL);
61
18.5k
    char yes[] = "yes";
62
18.5k
    globalParams->setEnableFreeType(yes);  // Yes, it's a string and not a bool.
63
18.5k
    globalParams->setErrQuiet(1);
64
65
18.5k
    PDFDoc *doc = NULL;
66
18.5k
    try {
67
18.5k
      PDFDoc doc(stream);
68
18.5k
        if (doc.isOk() == gTrue)
69
17.7k
        {
70
17.7k
            doc.getNumPages();
71
17.7k
            doc.getOutline();
72
17.7k
            doc.getStructTreeRoot();
73
17.7k
            doc.getXRef();
74
17.7k
            doc.okToPrint(gTrue);
75
17.7k
            doc.okToCopy(gTrue);
76
17.7k
            doc.okToChange(gTrue);
77
17.7k
            doc.okToAddNotes(gTrue);
78
17.7k
            doc.isLinearized();
79
17.7k
            doc.getPDFVersion();
80
81
17.7k
            GString *metadata;
82
17.7k
            if ((metadata = doc.readMetadata())) {
83
1.29k
              (void)metadata->getCString();
84
1.29k
            }
85
17.7k
            delete metadata;
86
87
17.7k
            Object info;
88
17.7k
            doc.getDocInfo(&info);
89
17.7k
            if (info.isDict()) {
90
3.77k
              info.getDict();
91
3.77k
            }
92
17.7k
            info.free();
93
94
17.7k
            if ((acroForm = doc.getCatalog()->getAcroForm())->isDict()) {
95
1.45k
                acroForm->dictLookup("XFA", &xfa);
96
1.45k
                xfa.free();
97
1.45k
            }
98
99
199k
            for (size_t i = 1; i <= doc.getNumPages(); i++) {
100
181k
              doc.getLinks(i);
101
181k
              auto page = doc.getCatalog()->getPage(i);
102
181k
              if (!page->isOk()) {
103
0
                continue;
104
0
              }
105
181k
              page->getResourceDict();
106
181k
              page->getMetadata();
107
181k
              page->getResourceDict();
108
181k
            }
109
110
17.7k
            SplashColor paperColor = {0xff, 0xff, 0xff};
111
17.7k
            SplashOutputDev *splashOut = new SplashOutputDev(splashModeRGB8, 1, gFalse, paperColor);
112
17.7k
            splashOut->setNoComposite(gTrue);
113
17.7k
            splashOut->startDoc(doc.getXRef());
114
199k
            for (size_t i = 1; i <= doc.getNumPages(); ++i) {
115
181k
              doc.displayPage(splashOut, NULL, i, hdpi, vdpi, rotate, useMediaBox, crop, printing);
116
181k
            }
117
17.7k
            (void)splashOut->getBitmap();
118
119
17.7k
            delete splashOut;
120
17.7k
        }
121
18.5k
    } catch (...) {
122
123
37
    }
124
125
18.5k
    delete globalParams;
126
127
18.5k
    return 0;
128
18.5k
}
129