Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

Fix #9 Incorrect JPEG meta data #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ immeta, an image metadata inspection library in Rust
[travis]: https://img.shields.io/travis/netvl/immeta.svg?style=flat-square
[crates]: https://img.shields.io/crates/v/immeta.svg?style=flat-square

[Documentation](https://netvl.github.io/immeta/)
[Documentation](https://docs.rs/immeta/)

immeta is an image metadata processing library. It allows you to inspect metadata, that is,
image dimensions, color information, etc. of various image formats.
Expand All @@ -28,14 +28,18 @@ Just add a dependency to your `Cargo.toml`:

```toml
[dependencies]
immeta = "0.3"
immeta = "0.4"
```

You can see an example on how to use it in `tests/test.rs`.


## Changelog

### Version 0.4.0

* Updated num-traits dependency to 0.2.

### Version 0.3.6

* Updated arrayvec dependency to 0.4.
Expand Down
18 changes: 13 additions & 5 deletions src/formats/jpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,24 @@ fn find_marker<R: ?Sized, F>(r: &mut R, name: &str, mut matcher: F) -> Result<u8
}
}

fn skip_extra_makers<R: ?Sized + BufRead>(r: &mut R) -> Result<u8> {
loop {
let marker = try!(find_marker(r, "Extra", |_| true));
if is_sof_marker(marker) {
// return last (SOF) marker
return Ok(marker);
}
let size = try_if_eof!(r.read_u16::<BigEndian>(), "when reading some marker payload size");
let _ = r.skip_exact(size as u64 - 2);
}
}

impl LoadableMetadata for Metadata {
fn load<R: ?Sized + BufRead>(r: &mut R) -> Result<Metadata> {
// read SOI marker, it must be present in all JPEG files
try!(find_marker(r, "SOI", |m| m == 0xd8));

// XXX: do we need to check for APP0 JFIF marker? This doesn't seem strictly necessary
// XXX: to me, and it seems that other interchange formats are also possible.

// read SOF marker, it must also be present in all JPEG files
let marker = try!(find_marker(r, "SOF", is_sof_marker));
let marker = try!(skip_extra_makers(r));

// read and check SOF marker length
let size = try_if_eof!(r.read_u16::<BigEndian>(), "when reading SOF marker payload size");
Expand Down