mirror of
https://github.com/qpdf/qpdf.git
synced 2024-11-01 03:12:29 +00:00
232f5fc9f3
The jpeg library has some assembly code that is missed by the compiler instrumentation used by memory sanitization. There is a runtime environment variable that is used to work around this issue.
59 lines
1.0 KiB
C++
59 lines
1.0 KiB
C++
#include <qpdf/Pl_Discard.hh>
|
|
#include <qpdf/Pl_DCT.hh>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <cstdlib>
|
|
|
|
class FuzzHelper
|
|
{
|
|
public:
|
|
FuzzHelper(unsigned char const* data, size_t size);
|
|
void run();
|
|
|
|
private:
|
|
void doChecks();
|
|
|
|
unsigned char const* data;
|
|
size_t size;
|
|
};
|
|
|
|
FuzzHelper::FuzzHelper(unsigned char const* data, size_t size) :
|
|
data(data),
|
|
size(size)
|
|
{
|
|
}
|
|
|
|
void
|
|
FuzzHelper::doChecks()
|
|
{
|
|
Pl_Discard discard;
|
|
Pl_DCT p("decode", &discard);
|
|
p.write(const_cast<unsigned char*>(data), size);
|
|
p.finish();
|
|
}
|
|
|
|
void
|
|
FuzzHelper::run()
|
|
{
|
|
try
|
|
{
|
|
doChecks();
|
|
}
|
|
catch (std::runtime_error const& e)
|
|
{
|
|
std::cerr << "runtime_error: " << e.what() << std::endl;
|
|
}
|
|
}
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size)
|
|
{
|
|
#ifndef _WIN32
|
|
// Used by jpeg library to work around false positives in memory
|
|
// sanitizer.
|
|
setenv("JSIMD_FORCENONE", "1", 1);
|
|
#endif
|
|
FuzzHelper f(data, size);
|
|
f.run();
|
|
return 0;
|
|
}
|