Skip to content

Commit

Permalink
fixup: don't download unicode categories data (AFLplusplus#1732)
Browse files Browse the repository at this point in the history
* fixup: don't download unicode categories data

* whoops, document

* fmt

* ci

---------

Co-authored-by: toka <[email protected]>
  • Loading branch information
addisoncrump and tokatoka authored Dec 17, 2023
1 parent 2726a59 commit ef8ebd5
Show file tree
Hide file tree
Showing 6 changed files with 6,562 additions and 63 deletions.
51 changes: 0 additions & 51 deletions libafl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rustc-cfg=nightly");
#[cfg(feature = "unicode")]
{
// build_unicode_property_map()?;
}
Ok(())
}

Expand All @@ -20,52 +16,5 @@ fn main() -> Result<(), Box<dyn Error>> {
cfg!(all(not(docrs), not(feature = "nautilus"))),
"The 'nautilus' feature of libafl requires a nightly compiler"
);
#[cfg(feature = "unicode")]
{
// build_unicode_property_map()?;
}
Ok(())
}

#[cfg(feature = "unicode")]
fn build_unicode_property_map() -> Result<(), Box<dyn Error>> {
use std::{
env,
fs::File,
io::{BufWriter, Write},
path::PathBuf,
process::{Command, Stdio},
};

let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let ucd_dir = out_dir.join("ucd-dir");
let generated_file = out_dir.join("unicode_categories.rs");

std::fs::create_dir_all(&ucd_dir)?;

let zip_path = ucd_dir.join("ucd.zip");
let mut ucd_file = BufWriter::new(File::create(&zip_path)?);
for chunk in reqwest::blocking::get("https://www.unicode.org/Public/zipped/latest/UCD.zip")?
.bytes()?
.chunks(1 << 12)
{
ucd_file.write_all(chunk)?;
}
ucd_file.flush()?;
drop(ucd_file);

let mut zip_file = zip::ZipArchive::new(File::open(&zip_path)?)?;
zip_file.extract(&ucd_dir)?;
drop(zip_file);

std::fs::remove_file(zip_path)?;

let status = Command::new("ucd-generate")
.arg("general-category")
.arg(ucd_dir.as_os_str())
.stdout(Stdio::from(File::create(generated_file)?))
.status()?;
assert!(status.success());

Ok(())
}
2 changes: 1 addition & 1 deletion libafl/src/mutators/scheduled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where
fn schedule(&self, state: &mut S, input: &I) -> MutationId;

/// New default implementation for mutate.
/// Implementations must forward mutate() to this method
/// Implementations must forward `mutate()` to this method
fn scheduled_mutate(
&mut self,
state: &mut S,
Expand Down
15 changes: 6 additions & 9 deletions libafl/src/mutators/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ use crate::{
state::{HasCorpus, HasMaxSize, HasMetadata, HasRand},
};

/// Unicode category data, as used by string analysis and mutators.
#[allow(unused)]
#[allow(missing_docs)]
#[allow(clippy::redundant_static_lifetimes)]
pub mod unicode_categories;

/// Input which contains the context necessary to perform unicode mutations
pub type UnicodeInput = (BytesInput, StringIdentificationMetadata);

Expand Down Expand Up @@ -267,15 +273,6 @@ fn rand_replace_range<S: HasRand + HasMaxSize, F: Fn(&mut S) -> char>(
MutationResult::Mutated
}

/// Unicode category data, as used by string analysis and mutators.
pub mod unicode_categories {
#![allow(unused)]
#![allow(missing_docs)]
#![allow(clippy::redundant_static_lifetimes)]

include!(concat!(env!("OUT_DIR"), "/unicode_categories.rs"));
}

/// Mutator which randomly replaces a randomly selected range of bytes with bytes that preserve the
/// range's category
#[derive(Debug, Default)]
Expand Down
Loading

0 comments on commit ef8ebd5

Please sign in to comment.