initial integration of rust-brotli (#8722)

Rust-brotli is a popular compressor and decompressor for rust. It has 6
million downloads with 35k downloads every day. It is also a dependency
for a lot of rust libraries.
This commit is contained in:
code-terror 2022-10-10 11:06:29 -07:00 committed by GitHub
parent f3bf7a6a61
commit 5f5b6f4944
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 155 additions and 0 deletions

View File

@ -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

View File

@ -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/

View File

@ -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

View File

@ -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);
});

View File

@ -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");
});

View File

@ -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'