Skip to content

Commit bdee3b9

Browse files
committed
fuzz: Add target encode_decode_hbd
Share code with encode_decode such that the corpus can be reused. Bit-depth is decoded last so that all other parameters are shared.
1 parent 8374283 commit bdee3b9

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

fuzz/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ name = "encode_decode"
2828
path = "fuzz_targets/encode_decode.rs"
2929
required-features = ["rav1e/decode_test_dav1d"]
3030

31+
[[bin]]
32+
name = "encode_decode_hbd"
33+
path = "fuzz_targets/encode_decode_hbd.rs"
34+
required-features = ["rav1e/decode_test_dav1d"]
35+
3136
[[bin]]
3237
name = "encode"
3338
path = "fuzz_targets/encode.rs"

fuzz/fuzz_targets/encode_decode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
extern crate rav1e;
1313
use rav1e::fuzzing::*;
1414

15-
fuzz_target!(|data: DecodeTestParameters| {
15+
fuzz_target!(|data: DecodeTestParameters<u8>| {
1616
let _ = pretty_env_logger::try_init();
1717

1818
fuzz_encode_decode(data)
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2019-2021, The rav1e contributors. All rights reserved
2+
//
3+
// This source code is subject to the terms of the BSD 2 Clause License and
4+
// the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
5+
// was not distributed with this source code in the LICENSE file, you can
6+
// obtain it at www.aomedia.org/license/software. If the Alliance for Open
7+
// Media Patent License 1.0 was not distributed with this source code in the
8+
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
9+
10+
#![no_main]
11+
#[macro_use] extern crate libfuzzer_sys;
12+
extern crate rav1e;
13+
use rav1e::fuzzing::*;
14+
15+
fuzz_target!(|data: DecodeTestParameters<u16>| {
16+
let _ = pretty_env_logger::try_init();
17+
18+
fuzz_encode_decode(data)
19+
});

src/fuzzing.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// Media Patent License 1.0 was not distributed with this source code in the
88
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
99

10+
use std::marker::PhantomData;
1011
use std::sync::Arc;
1112

1213
use libfuzzer_sys::arbitrary::{Arbitrary, Error, Unstructured};
@@ -295,7 +296,7 @@ pub fn fuzz_encode(arbitrary: ArbitraryEncoder) {
295296
}
296297

297298
#[derive(Debug)]
298-
pub struct DecodeTestParameters {
299+
pub struct DecodeTestParameters<T: Pixel> {
299300
w: usize,
300301
h: usize,
301302
speed: usize,
@@ -312,9 +313,10 @@ pub struct DecodeTestParameters {
312313
tile_cols_log2: usize,
313314
tile_rows_log2: usize,
314315
still_picture: bool,
316+
pixel: PhantomData<T>,
315317
}
316318

317-
impl Arbitrary for DecodeTestParameters {
319+
impl<T: Pixel> Arbitrary for DecodeTestParameters<T> {
318320
fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self, Error> {
319321
let mut p = Self {
320322
w: u.int_in_range(16..=16 + 255)?,
@@ -338,7 +340,11 @@ impl Arbitrary for DecodeTestParameters {
338340
tile_cols_log2: u.int_in_range(0..=2)?,
339341
tile_rows_log2: u.int_in_range(0..=2)?,
340342
still_picture: bool::arbitrary(u)?,
343+
pixel: PhantomData,
341344
};
345+
if matches!(T::type_enum(), PixelType::U16) {
346+
p.bit_depth = *u.choose(&[8, 10, 12])?;
347+
}
342348
if !p.low_latency {
343349
p.switch_frame_interval = 0;
344350
}
@@ -350,10 +356,10 @@ impl Arbitrary for DecodeTestParameters {
350356
}
351357

352358
#[cfg(feature = "decode_test_dav1d")]
353-
pub fn fuzz_encode_decode(p: DecodeTestParameters) {
359+
pub fn fuzz_encode_decode<T: Pixel>(p: DecodeTestParameters<T>) {
354360
use crate::test_encode_decode::*;
355361

356-
let mut dec = get_decoder::<u8>("dav1d", p.w, p.h);
362+
let mut dec = get_decoder::<T>("dav1d", p.w, p.h);
357363
dec.encode_decode(
358364
p.w,
359365
p.h,

0 commit comments

Comments
 (0)