From 4facc3ab544192bd72504e6fe2f02016e6487829 Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:52:04 -0700 Subject: [PATCH] test(fuzz): Use jemalloc for fuzz tests --- fuzz/Cargo.toml | 1 + fuzz/fuzz_targets/fuzz_read.rs | 5 +++++ fuzz/fuzz_targets/fuzz_write.rs | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 33c8933b..39c1969f 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -12,6 +12,7 @@ cargo-fuzz = true libfuzzer-sys = "0.4" arbitrary = { version = "1.3.2", features = ["derive"] } replace_with = "0.1.7" +tikv-jemallocator = "0.5.4" [dependencies.zip] path = ".." diff --git a/fuzz/fuzz_targets/fuzz_read.rs b/fuzz/fuzz_targets/fuzz_read.rs index a5c5a3ff..78fe670e 100644 --- a/fuzz/fuzz_targets/fuzz_read.rs +++ b/fuzz/fuzz_targets/fuzz_read.rs @@ -1,10 +1,15 @@ #![no_main] + use libfuzzer_sys::fuzz_target; use std::io::{Read, Seek, SeekFrom}; +use tikv_jemallocator::Jemalloc; use zip::read::read_zipfile_from_stream; const MAX_BYTES_TO_READ: u64 = 1 << 24; +#[global_allocator] +static GLOBAL: Jemalloc = Jemalloc; + fn decompress_all(data: &[u8]) -> Result<(), Box> { let reader = std::io::Cursor::new(data); let mut zip = zip::ZipArchive::new(reader)?; diff --git a/fuzz/fuzz_targets/fuzz_write.rs b/fuzz/fuzz_targets/fuzz_write.rs index 4fa9ce4f..414de08d 100755 --- a/fuzz/fuzz_targets/fuzz_write.rs +++ b/fuzz/fuzz_targets/fuzz_write.rs @@ -7,8 +7,12 @@ use libfuzzer_sys::fuzz_target; use replace_with::replace_with_or_abort; use std::io::{Cursor, Read, Seek, Write}; use std::path::PathBuf; +use tikv_jemallocator::Jemalloc; use zip::unstable::path_to_string; +#[global_allocator] +static GLOBAL: Jemalloc = Jemalloc; + #[derive(Arbitrary, Clone)] pub enum BasicFileOperation<'k> { WriteNormalFile {