Skip to content

Instantly share code, notes, and snippets.

@MarekKnapek
Created May 13, 2024 00:24
Show Gist options
  • Save MarekKnapek/88c96953a441491c88a718d6481c723a to your computer and use it in GitHub Desktop.
Save MarekKnapek/88c96953a441491c88a718d6481c723a to your computer and use it in GitHub Desktop.
quick_and_dirty_test_of_bcomp.cpp
#include <string.h>
#define crash(x) do{ if(!(x)){ __debugbreak(); int volatile* volatile ptr; ptr = 0; *ptr = 0; } }while(false)
#define min(a, b) (((b) < (a)) ? (b) : (a))
void test_1(unsigned char const* const data, size_t const size) noexcept
{
uint8_t state[256];
struct bcomp_state state_out;
uint16_t bcomp_bits;
uint8_t decompressed[256];
if(!(size >= 256)){ return; }
memcpy(&state[0], data, 256);
compress_core(state, 256, &state_out, &bcomp_bits);
decompression_core(state_out.bytes, 256, 0, decompressed);
crash(memcmp(&state[0], &decompressed[0], 256) == 0);
}
void test_2(unsigned char const* const data, size_t const size) noexcept
{
struct bcomp_state state_out;
uint8_t decompressed[256];
if(!(size >= sizeof(state_out))){ return; }
memcpy(&state_out, data, sizeof(state_out));
decompression_core(state_out.bytes, 256, 0, decompressed);
}
extern "C" int LLVMFuzzerTestOneInput(unsigned char const* const data, size_t const size) noexcept
{
test_1(data, size);
test_2(data, size);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment