Skip to content

Commit

Permalink
workaround: account for more stupid camera JPEG headers
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstoik1 committed Apr 25, 2024
1 parent a4bce67 commit baf8a6c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/image/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,21 @@ impl From<u8> for ImageKind {
impl ImageKind {
/// # Is JPEG?
pub(crate) fn is_jpeg(src: &[u8]) -> bool {
const END: [u8; 2] = [0xFF, 0xD9];

12 < src.len() &&
src[..3] == [0xFF, 0xD8, 0xFF] &&
match src[3] {
0xE0 =>
src[6..11] == [b'J', b'F', b'I', b'F', 0x00] ||
src[src.len() - 2..] == [0xFF, 0xD9],
0xE1 => src[6..11] == [b'E', b'x', b'i', b'f', 0x00],
0xE8 => src[6..12] == [b'S', b'P', b'I', b'F', b'F', 0x00],
0xDB | 0xED | 0xEE => src[src.len() - 2..] == [0xFF, 0xD9],
src[src.len() - 2..] == END,
0xE1 => src[6..11] ==
[b'E', b'x', b'i', b'f', 0x00] ||
src[src.len() - 2..] == END,
0xE8 => src[6..12] ==
[b'S', b'P', b'I', b'F', b'F', 0x00] ||
src[src.len() - 2..] == END,
0xDB | 0xE2..=0xEF => src[src.len() - 2..] == END,
_ => false,
}
}
Expand Down

0 comments on commit baf8a6c

Please sign in to comment.