Skip to content

Commit 99ec83b

Browse files
committed
Add XPM decoder
1 parent 4712d7f commit 99ec83b

File tree

15 files changed

+1200
-2
lines changed

15 files changed

+1200
-2
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ publish = false
88
include = ["src", "tests/reference.rs"]
99

1010
[features]
11-
default = ["pcx", "xbm"]
11+
default = ["pcx", "xbm", "xpm"]
1212
pcx = ["dep:pcx"]
1313
xbm = []
14+
xpm = ["dep:x11r6colornames"]
1415

1516
[dependencies]
1617
image = { version = "0.25.5", default-features = false }
1718
pcx = { version = "0.2.4", optional = true }
19+
x11r6colornames = { git = "https://github.com/mstoeckl/x11r6colornames.git", rev = "11a60d038ce2a1253a603be2c7eb45ee8d066264", version = "1.0.0", optional = true }
1820

1921
[dev-dependencies]
2022
image = { version = "0.25.5", default-features = false, features = ["png"] }

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Decoding support for additional image formats beyond those provided by the [`ima
77
| --------- | -------------------- |
88
| PCX | [Wikipedia](https://en.wikipedia.org/wiki/PCX#PCX_file_format) |
99
| XBM | [Wikipedia](https://en.wikipedia.org/wiki/X_BitMap) |
10+
| XPM | [Wikipedia](https://en.wikipedia.org/wiki/X_PixMap) |
1011

1112
## New Formats
1213

deny.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ targets = [
1414
[licenses]
1515
confidence-threshold = 0.93
1616
allow = [
17+
"0BSD",
1718
"Apache-2.0 WITH LLVM-exception",
1819
"Apache-2.0",
1920
"BSD-2-Clause",
2021
"BSD-3-Clause",
22+
"CC0-1.0",
2123
"MIT",
24+
"X11",
2225
"MIT-0",
2326
"MPL-2.0",
2427
"Unicode-DFS-2016",

fuzz/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ image = { version = "0.25.5", default-features = false }
1414

1515
[dependencies.image-extras]
1616
path = ".."
17-
features = ["xbm"]
17+
features = ["xbm", "xpm"]
1818
[dependencies.libfuzzer-sys]
1919
version = "0.4"
2020

@@ -29,3 +29,7 @@ members = ["."]
2929
[[bin]]
3030
name = "fuzzer_script_xbm"
3131
path = "fuzzers/fuzzer_script_xbm.rs"
32+
33+
[[bin]]
34+
name = "fuzzer_script_xpm"
35+
path = "fuzzers/fuzzer_script_xpm.rs"

fuzz/fuzzers/fuzzer_script_xpm.rs

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

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ pub mod pcx;
2121
#[cfg(feature = "xbm")]
2222
pub mod xbm;
2323

24+
#[cfg(feature = "xpm")]
25+
pub mod xpm;
26+
2427
/// Register all enabled extra formats with the image crate.
2528
pub fn register() {
2629
image::hooks::register_decoding_hook(
@@ -38,4 +41,10 @@ pub fn register() {
3841
"bm".into(),
3942
Box::new(|r| Ok(Box::new(xbm::XbmDecoder::new(r)?))),
4043
);
44+
45+
image::hooks::register_decoding_hook(
46+
"xpm".into(),
47+
Box::new(|r| Ok(Box::new(xpm::XpmDecoder::new(r)?))),
48+
);
49+
image::hooks::register_format_detection_hook("xpm".into(), b"/* XPM */", None);
4150
}

0 commit comments

Comments
 (0)