Coverage Report

Created: 2025-07-11 06:50

/src/xpdf-4.05/build/fuzz_JBIG2.cc
Line
Count
Source
1
/*  Copyright 2022 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
40
#include "JBIG2Stream.h"
41
42
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
43
2.30k
{
44
2.30k
  FuzzedDataProvider fdp(data, size);
45
2.30k
  double hdpi = fdp.ConsumeFloatingPoint<double>();
46
2.30k
  double vdpi = fdp.ConsumeFloatingPoint<double>();
47
2.30k
  int rotate = fdp.ConsumeIntegral<int>();
48
2.30k
  bool useMediaBox = fdp.ConsumeBool();
49
2.30k
  bool crop = fdp.ConsumeBool();
50
2.30k
  bool printing = fdp.ConsumeBool();
51
2.30k
  std::vector<char> payload = fdp.ConsumeRemainingBytes<char>();
52
53
2.30k
  Object xpdf_obj;
54
2.30k
  xpdf_obj.initNull();
55
2.30k
  BaseStream *stream = new MemStream(payload.data(), 0, payload.size(), &xpdf_obj);
56
57
2.30k
  Object info, xfa;
58
2.30k
  Object *acroForm;
59
2.30k
  globalParams = new GlobalParams(NULL);
60
2.30k
  globalParams->setErrQuiet(1);
61
2.30k
  globalParams->setupBaseFonts(NULL);
62
2.30k
  char yes[] = "yes";
63
2.30k
  globalParams->setEnableFreeType(yes); // Yes, it's a string and not a bool.
64
2.30k
  globalParams->setErrQuiet(1);
65
66
2.30k
  PDFDoc *doc = NULL;
67
2.30k
  try
68
2.30k
  {
69
2.30k
    PDFDoc doc(stream);
70
2.30k
    if (doc.isOk() == gTrue)
71
1.24k
    {
72
1.24k
      XRef *xref = doc.getXRef();
73
1.24k
      int objNums = xref->getNumObjects();
74
1.24k
      Object currentObj;
75
70.0M
      for (int i = 0; i < objNums; ++i)
76
70.0M
      {
77
70.0M
        if (xref->fetch(i, 0, &currentObj)->isStream())
78
14.9k
        {
79
14.9k
          currentObj.getStream()->reset();
80
14.9k
        }
81
70.0M
      }
82
1.24k
      currentObj.free();
83
1.24k
    }
84
2.30k
  }
85
2.30k
  catch (...)
86
2.30k
  {
87
18
  }
88
89
2.30k
  delete globalParams;
90
91
2.30k
  return 0;
92
2.30k
}