Skip to content

Commit 76fce6b

Browse files
committed
Add XPM decoder
1 parent e7da413 commit 76fce6b

File tree

20 files changed

+2012
-6
lines changed

20 files changed

+2012
-6
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:image-x11r6colornames"]
1415

1516
[dependencies]
1617
image = { version = "0.25.5", default-features = false }
1718
pcx = { version = "0.2.4", optional = true }
19+
image-x11r6colornames = { path = 'image-x11r6colornames', 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ allow = [
1919
"BSD-2-Clause",
2020
"BSD-3-Clause",
2121
"MIT",
22+
"X11",
2223
"MIT-0",
2324
"MPL-2.0",
2425
"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_xbm.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#![no_main]
22
#[macro_use]
33
extern crate libfuzzer_sys;
4-
extern crate image_extras;
5-
extern crate image;
64

7-
use std::io::BufReader;
5+
use std::io::Cursor;
86
use image::ImageDecoder;
97

108
fuzz_target!(|data: &[u8]| {
11-
let reader = BufReader::new(data);
9+
let reader = Cursor::new(data);
1210
let Ok(mut decoder) = image_extras::xbm::XbmDecoder::new(reader) else {
1311
return;
1412
};

fuzz/fuzzers/fuzzer_script_xpm.rs

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

image-x11r6colornames/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "image-x11r6colornames"
3+
version = "1.0.0"
4+
license = "(MIT OR Apache-2.0) AND X11"
5+
rust-version = "1.17.0"
6+
description = "Color database matching X11R6"
7+
readme = "README.md"
8+
publish = false

image-x11r6colornames/LICENSE-X11

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (C) 1994 X Consortium
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to
5+
deal in the Software without restriction, including without limitation the
6+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7+
sell copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
17+
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
18+
TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
20+
Except as contained in this notice, the name of the X Consortium shall not
21+
be used in advertising or otherwise to promote the sale, use or other deal-
22+
ings in this Software without prior written authorization from the X Consor-
23+
tium.

image-x11r6colornames/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## X11R6 Color names
2+
3+
This mini-library contains the color names database (often referred to as
4+
`rgb.txt`) from X11R6, as a sorted array with names case folded. It has been
5+
separated out into a distinct crate because it is possible that databases of
6+
colors with names are copyrightable and therefore subject to the X11 license.
7+
Splitting out the list makes it easier for users of the `image-extras`, which
8+
uses this library if its `xpm` feature is enabled, to keep track of licensing
9+
information.
10+
11+
Only the color database itself (from 1994) is X11 licensed; everything since
12+
then is offered under `MIT OR Apache-2.0`.

0 commit comments

Comments
 (0)