Skip to content

Commit 6580780

Browse files
authored
Add a fuzzer script for PCX (and update image version, cargo-deny action) (#9)
1 parent 1f25528 commit 6580780

File tree

5 files changed

+65
-5
lines changed

5 files changed

+65
-5
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ jobs:
6161
runs-on: ubuntu-latest
6262
steps:
6363
- uses: actions/checkout@v4
64-
- uses: EmbarkStudios/cargo-deny-action@v1
64+
- uses: EmbarkStudios/cargo-deny-action@v2

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ default = ["pcx"]
1212
pcx = ["dep:pcx"]
1313

1414
[dependencies]
15-
image = { version = "0.25.5", default-features = false }
15+
image = { version = "0.25.8", default-features = false }
1616
pcx = { version = "0.2.4", optional = true }
1717

1818
[dev-dependencies]
19-
image = { version = "0.25.5", default-features = false, features = ["png"] }
19+
image = { version = "0.25.8", default-features = false, features = ["png"] }
2020
walkdir = "2.5.0"
2121

22-
[patch.crates-io]
23-
image = { git = "https://github.com/fintelia/image", branch = "decoding-hooks" }

fuzz/Cargo.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
[package]
3+
name = "image-fuzz"
4+
version = "0.0.1"
5+
authors = ["Automatically generated"]
6+
edition = "2021"
7+
publish = false
8+
9+
[package.metadata]
10+
cargo-fuzz = true
11+
12+
[dependencies]
13+
image = { version = "0.25.8", default-features = false }
14+
15+
[dependencies.image-extras]
16+
path = ".."
17+
features = []
18+
[dependencies.libfuzzer-sys]
19+
version = "0.4"
20+
21+
# Prevent this from interfering with workspaces
22+
[workspace]
23+
members = ["."]
24+
25+
[[bin]]
26+
name = "fuzzer_script_pcx"
27+
path = "fuzzers/fuzzer_script_pcx.rs"

fuzz/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Fuzzing with libfuzzer
2+
3+
For the possibly more up-to-date guide see <https://fuzz.rs/book/cargo-fuzz/setup.html>.
4+
5+
> $ cargo install cargo-fuzz
6+
> $ cargo +nightly fuzz run fuzzer_script_<format>
7+
8+
# Bug reports
9+
10+
As explained in the project [README](../README.md), fuzzing is not a priority for
11+
this crate and decoders may panic or worse on malformed input. Please do not
12+
open issues for crashes found by fuzzing, unless they are memory safety violations,
13+
though PRs fixing them are welcome.

fuzz/fuzzers/fuzzer_script_pcx.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![no_main]
2+
#[macro_use]
3+
extern crate libfuzzer_sys;
4+
5+
use image::ImageDecoder;
6+
use std::io::Cursor;
7+
8+
fuzz_target!(|data: &[u8]| {
9+
let reader = Cursor::new(data);
10+
let Ok(mut decoder) = image_extras::pcx::PCXDecoder::new(reader) else {
11+
return;
12+
};
13+
let mut limits = image::Limits::default();
14+
limits.max_alloc = Some(1024 * 1024); // 1 MiB
15+
if limits.reserve(decoder.total_bytes()).is_err() {
16+
return;
17+
}
18+
if decoder.set_limits(limits).is_err() {
19+
return;
20+
}
21+
let _ = std::hint::black_box(image::DynamicImage::from_decoder(decoder));
22+
});

0 commit comments

Comments
 (0)