Coverage Report

Created: 2026-03-07 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xpdf-4.06/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
534
{
44
534
  FuzzedDataProvider fdp(data, size);
45
534
  double hdpi = fdp.ConsumeFloatingPoint<double>();
46
534
  double vdpi = fdp.ConsumeFloatingPoint<double>();
47
534
  int rotate = fdp.ConsumeIntegral<int>();
48
534
  bool useMediaBox = fdp.ConsumeBool();
49
534
  bool crop = fdp.ConsumeBool();
50
534
  bool printing = fdp.ConsumeBool();
51
534
  std::vector<char> payload = fdp.ConsumeRemainingBytes<char>();
52
53
534
  Object xpdf_obj;
54
534
  xpdf_obj.initNull();
55
534
  BaseStream *stream = new MemStream(payload.data(), 0, payload.size(), &xpdf_obj);
56
57
534
  Object info, xfa;
58
534
  Object *acroForm;
59
534
  globalParams = new GlobalParams(NULL);
60
534
  globalParams->setErrQuiet(1);
61
534
  globalParams->setupBaseFonts(NULL);
62
534
  char yes[] = "yes";
63
534
  globalParams->setEnableFreeType(yes); // Yes, it's a string and not a bool.
64
534
  globalParams->setErrQuiet(1);
65
66
534
  PDFDoc *doc = NULL;
67
534
  try
68
534
  {
69
534
    PDFDoc doc(stream);
70
534
    if (doc.isOk() == gTrue)
71
380
    {
72
380
      XRef *xref = doc.getXRef();
73
380
      int objNums = xref->getNumObjects();
74
380
      Object currentObj;
75
19.1M
      for (int i = 0; i < objNums; ++i)
76
19.1M
      {
77
19.1M
        if (xref->fetch(i, 0, &currentObj)->isStream())
78
4.95k
        {
79
4.95k
          currentObj.getStream()->reset();
80
4.95k
        }
81
19.1M
      }
82
380
      currentObj.free();
83
380
    }
84
534
  }
85
534
  catch (...)
86
534
  {
87
2
  }
88
89
534
  delete globalParams;
90
91
534
  return 0;
92
534
}