Separate JBIG2 fuzzer (#7523)

* Separate JBIG2 fuzzer

* fix copyright string
This commit is contained in:
Navidem 2022-04-06 18:45:37 -07:00 committed by GitHub
parent b1d19b1cd6
commit 1414080bf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 93 additions and 11 deletions

View File

@ -46,7 +46,7 @@ cmake ../ -DCMAKE_C_FLAGS="$CFLAGS" -DCMAKE_CXX_FLAGS="$CXXFLAGS" \
make
# Build fuzzers
for fuzzer in zxdoc pdfload; do
for fuzzer in zxdoc pdfload JBIG2; do
cp ../../fuzz_$fuzzer.cc .
$CXX fuzz_$fuzzer.cc -o $OUT/fuzz_$fuzzer $CXXFLAGS $LIB_FUZZING_ENGINE \
./xpdf/libtestXpdfStatic.a ./fofi/libfofi.a ./goo/libgoo.a ./splash/libsplash.a ./xpdf/libtestXpdfWidgetStatic.a /work/prefix/lib/libfreetype.a \

View File

@ -0,0 +1,92 @@
/* Copyright 2022 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <fuzzer/FuzzedDataProvider.h>
#include <vector>
#include <aconf.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <png.h>
#include "gmem.h"
#include "gmempp.h"
#include "parseargs.h"
#include "GString.h"
#include "gfile.h"
#include "GlobalParams.h"
#include "Object.h"
#include "PDFDoc.h"
#include "SplashBitmap.h"
#include "Splash.h"
#include "SplashOutputDev.h"
#include "Stream.h"
#include "config.h"
#include "JBIG2Stream.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
FuzzedDataProvider fdp(data, size);
double hdpi = fdp.ConsumeFloatingPoint<double>();
double vdpi = fdp.ConsumeFloatingPoint<double>();
int rotate = fdp.ConsumeIntegral<int>();
bool useMediaBox = fdp.ConsumeBool();
bool crop = fdp.ConsumeBool();
bool printing = fdp.ConsumeBool();
std::vector<char> payload = fdp.ConsumeRemainingBytes<char>();
Object xpdf_obj;
xpdf_obj.initNull();
BaseStream *stream = new MemStream(payload.data(), 0, payload.size(), &xpdf_obj);
Object info, xfa;
Object *acroForm;
globalParams = new GlobalParams(NULL);
globalParams->setErrQuiet(1);
globalParams->setupBaseFonts(NULL);
char yes[] = "yes";
globalParams->setEnableFreeType(yes); // Yes, it's a string and not a bool.
globalParams->setErrQuiet(1);
PDFDoc *doc = NULL;
try
{
PDFDoc doc(stream);
if (doc.isOk() == gTrue)
{
XRef *xref = doc.getXRef();
int objNums = xref->getNumObjects();
Object currentObj;
for (int i = 0; i < objNums; ++i)
{
if (xref->fetch(i, 0, &currentObj)->isStream())
{
currentObj.getStream()->reset();
}
}
currentObj.free();
}
}
catch (...)
{
}
delete globalParams;
return 0;
}

View File

@ -117,16 +117,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
(void)splashOut->getBitmap();
delete splashOut;
XRef *xref = doc.getXRef();
int objNums = xref->getNumObjects();
Object currentObj;
for (int i = 0; i < objNums; ++i) {
if (xref->fetch(i, 0, &currentObj)->isStream()){
currentObj.getStream()->reset();
}
}
currentObj.free();
}
} catch (...) {