mirror of https://github.com/google/oss-fuzz.git
Separate JBIG2 fuzzer (#7523)
* Separate JBIG2 fuzzer * fix copyright string
This commit is contained in:
parent
b1d19b1cd6
commit
1414080bf7
|
@ -46,7 +46,7 @@ cmake ../ -DCMAKE_C_FLAGS="$CFLAGS" -DCMAKE_CXX_FLAGS="$CXXFLAGS" \
|
||||||
make
|
make
|
||||||
|
|
||||||
# Build fuzzers
|
# Build fuzzers
|
||||||
for fuzzer in zxdoc pdfload; do
|
for fuzzer in zxdoc pdfload JBIG2; do
|
||||||
cp ../../fuzz_$fuzzer.cc .
|
cp ../../fuzz_$fuzzer.cc .
|
||||||
$CXX fuzz_$fuzzer.cc -o $OUT/fuzz_$fuzzer $CXXFLAGS $LIB_FUZZING_ENGINE \
|
$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 \
|
./xpdf/libtestXpdfStatic.a ./fofi/libfofi.a ./goo/libgoo.a ./splash/libsplash.a ./xpdf/libtestXpdfWidgetStatic.a /work/prefix/lib/libfreetype.a \
|
||||||
|
|
|
@ -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, ¤tObj)->isStream())
|
||||||
|
{
|
||||||
|
currentObj.getStream()->reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currentObj.free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
delete globalParams;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -117,16 +117,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||||
(void)splashOut->getBitmap();
|
(void)splashOut->getBitmap();
|
||||||
|
|
||||||
delete splashOut;
|
delete splashOut;
|
||||||
|
|
||||||
XRef *xref = doc.getXRef();
|
|
||||||
int objNums = xref->getNumObjects();
|
|
||||||
Object currentObj;
|
|
||||||
for (int i = 0; i < objNums; ++i) {
|
|
||||||
if (xref->fetch(i, 0, ¤tObj)->isStream()){
|
|
||||||
currentObj.getStream()->reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
currentObj.free();
|
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue