Skip to content

Commit d57b157

Browse files
committed
Add fuzz targets for subsampling
1 parent 261a21c commit d57b157

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

fuzz/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,15 @@ name = "encode_rgb_custom_q_table"
4141
path = "fuzz_targets/encode_rgb_custom_q_table.rs"
4242
test = false
4343
doc = false
44+
45+
[[bin]]
46+
name = "encode_rgb_subsampled"
47+
path = "fuzz_targets/encode_rgb_subsampled.rs"
48+
test = false
49+
doc = false
50+
51+
[[bin]]
52+
name = "encode_rgb_progressive"
53+
path = "fuzz_targets/encode_rgb_progressive.rs"
54+
test = false
55+
doc = false
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![no_main]
2+
3+
use libfuzzer_sys::fuzz_target;
4+
5+
use jpeg_encoder::*;
6+
7+
fuzz_target!(|data: &[u8]| {
8+
9+
let pixels = data.len() / 3;
10+
11+
let width = (pixels as f64).sqrt() as u16;
12+
let height = width;
13+
14+
if width >0 && width < u16::MAX && height >0 && height < u16::MAX {
15+
let mut out = Vec::new();
16+
let mut encoder = Encoder::new(&mut out, 80);
17+
encoder.set_sampling_factor(SamplingFactor::F_2_2);
18+
encoder.set_progressive(true);
19+
encoder.encode(data, width as u16, height as u16, ColorType::Rgb).unwrap();
20+
}
21+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![no_main]
2+
3+
use libfuzzer_sys::fuzz_target;
4+
5+
use jpeg_encoder::*;
6+
7+
fuzz_target!(|data: &[u8]| {
8+
9+
let pixels = data.len() / 3;
10+
11+
let width = (pixels as f64).sqrt() as u16;
12+
let height = width;
13+
14+
if width >0 && width < u16::MAX && height >0 && height < u16::MAX {
15+
let mut out = Vec::new();
16+
let mut encoder = Encoder::new(&mut out, 80);
17+
encoder.set_sampling_factor(SamplingFactor::F_4_2);
18+
encoder.encode(data, width as u16, height as u16, ColorType::Rgb).unwrap();
19+
}
20+
});

0 commit comments

Comments
 (0)