From f397a2f89cf3a3e445bf44967aac1f77311740f2 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Thu, 2 Jul 2020 03:25:05 +0200 Subject: [PATCH] Fuzz with 3kb, 8kb --- fuzzing/MockedBroadcastingEchoServer.cpp | 2 +- fuzzing/PerMessageDeflate.cpp | 76 ++++++++++++------------ 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/fuzzing/MockedBroadcastingEchoServer.cpp b/fuzzing/MockedBroadcastingEchoServer.cpp index 264999a..11c3620 100644 --- a/fuzzing/MockedBroadcastingEchoServer.cpp +++ b/fuzzing/MockedBroadcastingEchoServer.cpp @@ -18,7 +18,7 @@ extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { /* Very simple WebSocket echo server */ app = new uWS::TemplatedApp(uWS::App().ws("/*", { /* Settings */ - .compression = uWS::DEDICATED_COMPRESSOR_3KB, + .compression = uWS::DEDICATED_COMPRESSOR_8KB, /* We want this to be low so that we can hit it, yet bigger than 256 */ .maxPayloadLength = 300, .idleTimeout = 10, diff --git a/fuzzing/PerMessageDeflate.cpp b/fuzzing/PerMessageDeflate.cpp index 136d81a..2900a88 100644 --- a/fuzzing/PerMessageDeflate.cpp +++ b/fuzzing/PerMessageDeflate.cpp @@ -1,38 +1,38 @@ -/* This is a fuzz test of the permessage-deflate module */ - -#define WIN32_EXPORT - -#include -#include - -/* We test the permessage deflate module */ -#include "../src/PerMessageDeflate.h" - -#include "helpers.h" - -struct StaticData { - uWS::ZlibContext zlibContext; - - uWS::InflationStream inflationStream; - uWS::DeflationStream deflationStream = uWS::DEDICATED_COMPRESSOR_8KB; -} staticData; - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - - /* Why is this padded? */ - makeChunked(makePadded(data, size), size, [](const uint8_t *data, size_t size) { - auto [inflation, valid] = staticData.inflationStream.inflate(&staticData.zlibContext, std::string_view((char *) data, size), 256); - if (inflation.length() > 256) { - /* Cause ASAN to freak out */ - delete (int *) (void *) 1; - } - }); - - makeChunked(makePadded(data, size), size, [](const uint8_t *data, size_t size) { - /* Always reset */ - staticData.deflationStream.deflate(&staticData.zlibContext, std::string_view((char *) data, size), true); - }); - - return 0; -} - +/* This is a fuzz test of the permessage-deflate module */ + +#define WIN32_EXPORT + +#include +#include + +/* We test the permessage deflate module */ +#include "../src/PerMessageDeflate.h" + +#include "helpers.h" + +struct StaticData { + uWS::ZlibContext zlibContext; + + uWS::InflationStream inflationStream; + uWS::DeflationStream deflationStream = uWS::DEDICATED_COMPRESSOR_3KB; +} staticData; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + + /* Why is this padded? */ + makeChunked(makePadded(data, size), size, [](const uint8_t *data, size_t size) { + auto [inflation, valid] = staticData.inflationStream.inflate(&staticData.zlibContext, std::string_view((char *) data, size), 256); + if (inflation.length() > 256) { + /* Cause ASAN to freak out */ + delete (int *) (void *) 1; + } + }); + + makeChunked(makePadded(data, size), size, [](const uint8_t *data, size_t size) { + /* Always reset */ + staticData.deflationStream.deflate(&staticData.zlibContext, std::string_view((char *) data, size), true); + }); + + return 0; +} +