diff --git a/projects/rust-brotli/Dockerfile b/projects/rust-brotli/Dockerfile new file mode 100644 index 000000000..158dfcf7b --- /dev/null +++ b/projects/rust-brotli/Dockerfile @@ -0,0 +1,22 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +FROM gcr.io/oss-fuzz-base/base-builder-rust as builder + +## Install build dependencies. +RUN apt-get update +RUN git clone --depth 1 https://github.com/dropbox/rust-brotli +COPY build.sh $SRC/ +COPY /fuzz $SRC/rust-brotli/fuzz \ No newline at end of file diff --git a/projects/rust-brotli/build.sh b/projects/rust-brotli/build.sh new file mode 100644 index 000000000..329f9bce6 --- /dev/null +++ b/projects/rust-brotli/build.sh @@ -0,0 +1,19 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +cd $SRC/rust-brotli/fuzz +cargo fuzz build +cp $SRC/rust-brotli/fuzz/target/x86_64-unknown-linux-gnu/release/decompress $OUT/ +cp $SRC/rust-brotli/fuzz/target/x86_64-unknown-linux-gnu/release/roundtrip $OUT/ \ No newline at end of file diff --git a/projects/rust-brotli/fuzz/Cargo.toml b/projects/rust-brotli/fuzz/Cargo.toml new file mode 100644 index 000000000..c040c93b8 --- /dev/null +++ b/projects/rust-brotli/fuzz/Cargo.toml @@ -0,0 +1,46 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +[package] +name = "brotli-fuzz" +version = "0.0.0" +authors = ["Automatically generated"] +publish = false +edition = "2018" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" + +[dependencies.brotli] +path = ".." + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[[bin]] +name = "roundtrip" +path = "fuzz_targets/roundtrip.rs" +test = false +doc = false + +[[bin]] +name = "decompress" +path = "fuzz_targets/decompress.rs" +test = false +doc = false diff --git a/projects/rust-brotli/fuzz/fuzz_targets/decompress.rs b/projects/rust-brotli/fuzz/fuzz_targets/decompress.rs new file mode 100644 index 000000000..f1268b57f --- /dev/null +++ b/projects/rust-brotli/fuzz/fuzz_targets/decompress.rs @@ -0,0 +1,26 @@ +/* +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +*/ +#![no_main] +use libfuzzer_sys::fuzz_target; +use std::io::{Read, Write}; + +fuzz_target!(|data: (u16, &[u8])| { + let sink = std::io::sink(); + let mut decompressor = brotli::DecompressorWriter::new(sink, data.0.into()); + let _ = decompressor.write_all(data.1); +}); diff --git a/projects/rust-brotli/fuzz/fuzz_targets/roundtrip.rs b/projects/rust-brotli/fuzz/fuzz_targets/roundtrip.rs new file mode 100644 index 000000000..7f381a653 --- /dev/null +++ b/projects/rust-brotli/fuzz/fuzz_targets/roundtrip.rs @@ -0,0 +1,31 @@ +/* +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +*/ +#![no_main] +use libfuzzer_sys::fuzz_target; +use std::io::{Read, Write}; + +fuzz_target!(|data: (u16, u32, u32, &[u8], u16)| { + let mut compressed = Vec::new(); + let mut writer = brotli::CompressorWriter::new(&mut compressed, data.0.into(), data.1, data.2); + writer.write_all(data.3).unwrap(); + drop(writer); + let mut reader = brotli::Decompressor::new(compressed.as_slice(), data.4.into()); + let mut decompressed = Vec::with_capacity(data.3.len()); + let _ = reader.read_to_end(&mut decompressed); + assert_eq!(data.3, decompressed, "roundtrip failed"); +}); diff --git a/projects/rust-brotli/project.yaml b/projects/rust-brotli/project.yaml new file mode 100644 index 000000000..69564a5e7 --- /dev/null +++ b/projects/rust-brotli/project.yaml @@ -0,0 +1,11 @@ +homepage: "https://github.com/dropbox/rust-brotli" +language: rust +primary_contact: "danielrh@users.sourceforge.net" +auto_ccs: + - "github@nemo157.com" + - "vmaturi@asu.edu" +sanitizers: + - address +fuzzing_engines: + - libfuzzer +main_repo: 'https://github.com/dropbox/rust-brotli' \ No newline at end of file