-
Notifications
You must be signed in to change notification settings - Fork 3
Draft: Add support for XBM and XPM #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mstoeckl
wants to merge
4
commits into
image-rs:main
Choose a base branch
from
mstoeckl:xpm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ allow = [ | |
"BSD-2-Clause", | ||
"BSD-3-Clause", | ||
"MIT", | ||
"X11", | ||
"MIT-0", | ||
"MPL-2.0", | ||
"Unicode-DFS-2016", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//! An example of opening an image. | ||
extern crate image; | ||
extern crate image_extras; | ||
|
||
use std::env; | ||
use std::error::Error; | ||
use std::path::Path; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
image_extras::register(); | ||
|
||
let (from, into) = if env::args_os().count() == 3 { | ||
( | ||
env::args_os().nth(1).unwrap(), | ||
env::args_os().nth(2).unwrap(), | ||
) | ||
} else { | ||
println!("Please enter a from and into path."); | ||
std::process::exit(1); | ||
}; | ||
|
||
// Use the open function to load an image from a Path. | ||
// ```open``` returns a dynamic image. | ||
let im = image::open(Path::new(&from)).unwrap(); | ||
// Write the contents of this image using extension guessing. | ||
im.save(Path::new(&into)).unwrap(); | ||
Ok(()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
[package] | ||
name = "image-fuzz" | ||
version = "0.0.1" | ||
authors = ["Automatically generated"] | ||
edition = "2021" | ||
publish = false | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
image = { version = "0.25.5", default-features = false } | ||
|
||
[dependencies.image-extras] | ||
path = ".." | ||
features = ["xbm", "xpm"] | ||
[dependencies.libfuzzer-sys] | ||
version = "0.4" | ||
|
||
# Temporarily needed for image-extras to build, see ../Cargo.toml | ||
[patch.crates-io] | ||
image = { git = "https://github.com/fintelia/image", branch = "decoding-hooks" } | ||
|
||
# Prevent this from interfering with workspaces | ||
[workspace] | ||
members = ["."] | ||
|
||
[[bin]] | ||
name = "fuzzer_script_xbm" | ||
path = "fuzzers/fuzzer_script_xbm.rs" | ||
|
||
[[bin]] | ||
name = "fuzzer_script_xpm" | ||
path = "fuzzers/fuzzer_script_xpm.rs" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Fuzzing with libfuzzer | ||
|
||
For the possibly more up-to-date guide see <https://fuzz.rs/book/cargo-fuzz/setup.html>. | ||
|
||
> $ cargo install cargo-fuzz | ||
> $ cargo +nightly fuzz run fuzzer_script_<format> | ||
|
||
Fuzzing may progress faster for certain formats if seeded with a dictionary: | ||
|
||
> $ cargo +nightly fuzz run fuzzer_script_xbm -- -dict=fuzz/dictionaries/xbm.dict | ||
|
||
# Bug reports | ||
|
||
As explained in the project [README](../README.md), fuzzing is not a priority for | ||
this crate and decoders may panic or worse on malformed input. Please do not | ||
open issues for crashes found by fuzzing, though PRs fixing them are welcome. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"#define" | ||
"_width" | ||
"_height" | ||
"_x_hot" | ||
"_y_hot" | ||
"static" | ||
"unsigned" | ||
"char" | ||
"_bits[]" | ||
"=" | ||
"{" | ||
"0x" | ||
"0X" | ||
"," | ||
"}" | ||
";" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#![no_main] | ||
#[macro_use] | ||
extern crate libfuzzer_sys; | ||
|
||
use std::io::Cursor; | ||
use image::ImageDecoder; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let reader = Cursor::new(data); | ||
let Ok(mut decoder) = image_extras::xbm::XbmDecoder::new(reader) else { | ||
return; | ||
}; | ||
let mut limits = image::Limits::default(); | ||
limits.max_alloc = Some(1024 * 1024); // 1 MiB | ||
if limits.reserve(decoder.total_bytes()).is_err() { | ||
return; | ||
} | ||
if decoder.set_limits(limits).is_err() { | ||
return; | ||
} | ||
let _ = std::hint::black_box(image::DynamicImage::from_decoder(decoder)); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#![no_main] | ||
#[macro_use] extern crate libfuzzer_sys; | ||
|
||
use std::io::Cursor; | ||
use image::ImageDecoder; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let reader = Cursor::new(data); | ||
let Ok(mut decoder) = image_extras::xpm::XpmDecoder::new(reader) else { | ||
return; | ||
}; | ||
let mut limits = image::Limits::default(); | ||
limits.max_alloc = Some(1024 * 1024); // 1 MiB | ||
if limits.reserve(decoder.total_bytes()).is_err() { | ||
return; | ||
} | ||
if decoder.set_limits(limits).is_err() { | ||
return; | ||
} | ||
let _ = std::hint::black_box(image::DynamicImage::from_decoder(decoder)); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "image-x11r6colors" | ||
version = "1.0.0" | ||
license = "(MIT OR Apache-2.0) AND X11" | ||
rust-version = "1.17.0" | ||
description = "Color database matching X11R6" | ||
readme = "README.md" | ||
publish = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Copyright (C) 1994 X Consortium | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to | ||
deal in the Software without restriction, including without limitation the | ||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
sell copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | ||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- | ||
TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
Except as contained in this notice, the name of the X Consortium shall not | ||
be used in advertising or otherwise to promote the sale, use or other deal- | ||
ings in this Software without prior written authorization from the X Consor- | ||
tium. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## X11R6 Color names | ||
|
||
This mini-library contains the color names database (often referred to as | ||
`rgb.txt`) from X11R6, as a sorted array with names case folded. It has been | ||
separated out into a distinct crate because it is possible that databases of | ||
colors with names are copyrightable and therefore subject to the X11 license. | ||
Splitting out the list makes it easier for users of the `image-extras`, which | ||
uses this library if its `xpm` feature is enabled, to keep track of licensing | ||
information. | ||
|
||
Only the color database itself (from 1994) is X11 licensed; everything since | ||
then is offered under `MIT OR Apache-2.0`. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth having this also reference the note in the crate README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (linked to the README and repeated part of the note).