Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions fuzz/box_f32/box_f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#![no_main]

use arbitrary::Arbitrary;
use libblur::{BlurImage, BlurImageMut, BoxBlurParameters, FastBlurChannels, ThreadingPolicy};
use libblur::{
BlurImage, BlurImageMut, BoxBlurParameters, BufferStore, FastBlurChannels, ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;

#[derive(Clone, Debug, Arbitrary)]
Expand All @@ -43,6 +45,7 @@ pub struct SrcImage {
pub y_kernel_size: u8,
pub plane: u8,
pub threading: bool,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand All @@ -60,7 +63,7 @@ fuzz_target!(|data: SrcImage| {
1 => FastBlurChannels::Channels3,
_ => FastBlurChannels::Plane,
};
fuzz_16bit(
fuzz_f32(
data.src_width as usize,
data.src_height as usize,
data.x_kernel_size as usize,
Expand All @@ -71,23 +74,41 @@ fuzz_target!(|data: SrcImage| {
} else {
ThreadingPolicy::Single
},
data.additional_padding as usize % 50,
);
});

fn fuzz_16bit(
fn fuzz_f32(
width: usize,
height: usize,
x_kernel_size: usize,
y_kernel_size: usize,
channels: FastBlurChannels,
threading_policy: ThreadingPolicy,
additional_padding: usize,
) {
if width == 0 || height == 0 || x_kernel_size == 0 || y_kernel_size == 0 {
return;
}
let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);
let src_image = BlurImage::alloc(width as u32, height as u32, channels);

let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let src_image = vec![0.5; stride as usize * (height - 1) + width * channels.channels()];
let dst_image = vec![0.; stride as usize * (height - 1) + width * channels.channels()];

let src_image = BlurImage {
data: std::borrow::Cow::Borrowed(&src_image),
width: width as u32,
height: height as u32,
stride,
channels,
};
let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};
libblur::box_blur_f32(
&src_image,
&mut dst_image,
Expand Down
28 changes: 25 additions & 3 deletions fuzz/box_u16/box_u16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#![no_main]

use arbitrary::Arbitrary;
use libblur::{BlurImage, BlurImageMut, BoxBlurParameters, FastBlurChannels, ThreadingPolicy};
use libblur::{
BlurImage, BlurImageMut, BoxBlurParameters, BufferStore, FastBlurChannels, ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;

#[derive(Clone, Debug, Arbitrary)]
Expand All @@ -43,6 +45,7 @@ pub struct SrcImage {
pub y_kernel_size: u8,
pub plane: u8,
pub threading: bool,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand Down Expand Up @@ -71,6 +74,7 @@ fuzz_target!(|data: SrcImage| {
} else {
ThreadingPolicy::Single
},
data.additional_padding as usize % 50,
);
});

Expand All @@ -81,12 +85,30 @@ fn fuzz_16bit(
y_kernel_size: usize,
channels: FastBlurChannels,
threading_policy: ThreadingPolicy,
additional_padding: usize,
) {
if width == 0 || height == 0 || x_kernel_size == 0 || y_kernel_size == 0 {
return;
}
let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);
let src_image = BlurImage::alloc(width as u32, height as u32, channels);

let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let src_image = vec![1u16; stride as usize * (height - 1) + width * channels.channels()];
let dst_image = vec![0u16; stride as usize * (height - 1) + width * channels.channels()];

let src_image = BlurImage {
data: std::borrow::Cow::Borrowed(&src_image),
width: width as u32,
height: height as u32,
stride,
channels,
};
let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};

libblur::box_blur_u16(
&src_image,
Expand Down
20 changes: 16 additions & 4 deletions fuzz/fast_gaussian_f32/fast_gaussian_f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

use arbitrary::Arbitrary;
use libblur::{
fast_gaussian_f32, AnisotropicRadius, BlurImageMut, EdgeMode, EdgeMode2D, FastBlurChannels,
ThreadingPolicy,
fast_gaussian_f32, AnisotropicRadius, BlurImageMut, BufferStore, EdgeMode, EdgeMode2D,
FastBlurChannels, ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;

Expand All @@ -45,6 +45,7 @@ pub struct SrcImage {
pub x_radius: u8,
pub y_radius: u8,
pub plane: u8,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand All @@ -70,6 +71,7 @@ fuzz_target!(|data: SrcImage| {
plane_match,
edge_mode,
data.value as f32 / 65535.0,
data.additional_padding as usize % 50,
);
});

Expand All @@ -81,12 +83,22 @@ fn fuzz_image(
channels: FastBlurChannels,
edge_mode: EdgeMode,
value: f32,
additional_padding: usize,
) {
if width == 0 || height == 0 {
return;
}
let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);
dst_image.data.borrow_mut().fill(value);

let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let dst_image = vec![value; stride as usize * (height - 1) + width * channels.channels()];

let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};

fast_gaussian_f32(
&mut dst_image,
Expand Down
18 changes: 15 additions & 3 deletions fuzz/fast_gaussian_next_f32/fast_gaussian_next_f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

use arbitrary::Arbitrary;
use libblur::{
fast_gaussian_next_f32, AnisotropicRadius, BlurImageMut, EdgeMode, EdgeMode2D,
fast_gaussian_next_f32, AnisotropicRadius, BlurImageMut, BufferStore, EdgeMode, EdgeMode2D,
FastBlurChannels, ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;
Expand All @@ -45,6 +45,7 @@ pub struct SrcImage {
pub x_radius: u8,
pub y_radius: u8,
pub plane: u8,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand All @@ -70,6 +71,7 @@ fuzz_target!(|data: SrcImage| {
plane_match,
edge_mode,
data.value as f32 / 65535.0,
data.additional_padding as usize % 50,
);
});

Expand All @@ -81,12 +83,22 @@ fn fuzz_image(
channels: FastBlurChannels,
edge_mode: EdgeMode,
value: f32,
additional_padding: usize,
) {
if width == 0 || height == 0 {
return;
}
let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);
dst_image.data.borrow_mut().fill(value);

let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let dst_image = vec![value; stride as usize * (height - 1) + width * channels.channels()];

let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};

fast_gaussian_next_f32(
&mut dst_image,
Expand Down
18 changes: 15 additions & 3 deletions fuzz/fast_gaussian_next_u16/fast_gaussian_next_u16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

use arbitrary::Arbitrary;
use libblur::{
fast_gaussian_next_u16, AnisotropicRadius, BlurImageMut, EdgeMode, EdgeMode2D,
fast_gaussian_next_u16, AnisotropicRadius, BlurImageMut, BufferStore, EdgeMode, EdgeMode2D,
FastBlurChannels, ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;
Expand All @@ -45,6 +45,7 @@ pub struct SrcImage {
pub x_radius: u8,
pub y_radius: u8,
pub plane: u8,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand All @@ -70,6 +71,7 @@ fuzz_target!(|data: SrcImage| {
plane_match,
edge_mode,
data.value,
data.additional_padding as usize % 50,
);
});

Expand All @@ -81,12 +83,22 @@ fn fuzz_image(
channels: FastBlurChannels,
edge_mode: EdgeMode,
value: u16,
additional_padding: usize,
) {
if width == 0 || height == 0 {
return;
}
let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);
dst_image.data.borrow_mut().fill(value);

let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let dst_image = vec![value; stride as usize * (height - 1) + width * channels.channels()];

let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};

fast_gaussian_next_u16(
&mut dst_image,
Expand Down
20 changes: 16 additions & 4 deletions fuzz/fast_gaussian_u16/fast_gaussian_u16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

use arbitrary::Arbitrary;
use libblur::{
fast_gaussian_u16, AnisotropicRadius, BlurImageMut, EdgeMode, EdgeMode2D, FastBlurChannels,
ThreadingPolicy,
fast_gaussian_u16, AnisotropicRadius, BlurImageMut, BufferStore, EdgeMode, EdgeMode2D,
FastBlurChannels, ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;

Expand All @@ -45,6 +45,7 @@ pub struct SrcImage {
pub x_radius: u8,
pub y_radius: u8,
pub plane: u8,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand All @@ -70,6 +71,7 @@ fuzz_target!(|data: SrcImage| {
plane_match,
edge_mode,
data.value,
data.additional_padding as usize % 50,
);
});

Expand All @@ -81,12 +83,22 @@ fn fuzz_image(
channels: FastBlurChannels,
edge_mode: EdgeMode,
value: u16,
additional_padding: usize,
) {
if width == 0 || height == 0 {
return;
}
let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);
dst_image.data.borrow_mut().fill(value);

let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let dst_image = vec![value; stride as usize * (height - 1) + width * channels.channels()];

let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};

fast_gaussian_u16(
&mut dst_image,
Expand Down
27 changes: 24 additions & 3 deletions fuzz/motion/motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

use arbitrary::Arbitrary;
use libblur::{
BlurImage, BlurImageMut, EdgeMode, EdgeMode2D, FastBlurChannels, Scalar, ThreadingPolicy,
BlurImage, BlurImageMut, BufferStore, EdgeMode, EdgeMode2D, FastBlurChannels, Scalar,
ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;

Expand All @@ -45,6 +46,7 @@ pub struct SrcImage {
pub kernel_size: u8,
pub angle: f32,
pub threading: bool,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand Down Expand Up @@ -84,6 +86,7 @@ fuzz_target!(|data: SrcImage| {
channels,
EdgeMode2D::anisotropy(edge_mode_horizontal, edge_mode_vertical),
mp,
data.additional_padding as usize % 50,
);
});

Expand All @@ -95,12 +98,30 @@ fn fuzz_8bit(
channels: FastBlurChannels,
edge_mode: EdgeMode2D,
threading_policy: ThreadingPolicy,
additional_padding: usize,
) {
if width == 0 || height == 0 || radius == 0 {
return;
}
let src_image = BlurImage::alloc(width as u32, height as u32, channels);
let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);

let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let src_image = vec![0u8; stride as usize * (height - 1) + width * channels.channels()];
let dst_image = vec![0u8; stride as usize * (height - 1) + width * channels.channels()];

let src_image = BlurImage {
data: std::borrow::Cow::Borrowed(&src_image),
width: width as u32,
height: height as u32,
stride,
channels,
};
let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};

libblur::motion_blur(
&src_image,
Expand Down
Loading