Skip to content

Commit 168ee6b

Browse files
committed
Merge remote-tracking branch 'origin/master' into idct-scale
2 parents d28ea6f + 565a131 commit 168ee6b

File tree

8 files changed

+29
-41
lines changed

8 files changed

+29
-41
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: rust
22
rust:
3-
- 1.28.0
3+
- 1.34.2
44
- stable
55
- beta
66
- nightly

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ fn main() {
3232
```
3333

3434
## Requirements
35-
This crate compiles only with rust >= 1.28.
35+
This crate compiles only with rust >= 1.34.

src/decoder.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<R: Read> Decoder<R> {
251251
Marker::DQT => {
252252
let tables = parse_dqt(&mut self.reader)?;
253253

254-
for (i, &table) in tables.into_iter().enumerate() {
254+
for (i, &table) in tables.iter().enumerate() {
255255
if let Some(table) = table {
256256
let mut unzigzagged_table = [0u16; 64];
257257

@@ -352,23 +352,22 @@ impl<R: Read> Decoder<R> {
352352
}
353353

354354
fn read_marker(&mut self) -> Result<Marker> {
355-
// This should be an error as the JPEG spec doesn't allow extraneous data between marker segments.
356-
// libjpeg allows this though and there are images in the wild utilising it, so we are
357-
// forced to support this behavior.
358-
// Sony Ericsson P990i is an example of a device which produce this sort of JPEGs.
359-
while self.reader.read_u8()? != 0xFF {}
360-
361-
let mut byte = self.reader.read_u8()?;
362-
363-
// Section B.1.1.2
364-
// "Any marker may optionally be preceded by any number of fill bytes, which are bytes assigned code X’FF’."
365-
while byte == 0xFF {
366-
byte = self.reader.read_u8()?;
367-
}
368-
369-
match byte {
370-
0x00 => Err(Error::Format("FF 00 found where marker was expected".to_owned())),
371-
_ => Ok(Marker::from_u8(byte).unwrap()),
355+
loop {
356+
// This should be an error as the JPEG spec doesn't allow extraneous data between marker segments.
357+
// libjpeg allows this though and there are images in the wild utilising it, so we are
358+
// forced to support this behavior.
359+
// Sony Ericsson P990i is an example of a device which produce this sort of JPEGs.
360+
while self.reader.read_u8()? != 0xFF {}
361+
362+
// Section B.1.1.2
363+
// All markers are assigned two-byte codes: an X’FF’ byte followed by a
364+
// byte which is not equal to 0 or X’FF’ (see Table B.1). Any marker may
365+
// optionally be preceded by any number of fill bytes, which are bytes
366+
// assigned code X’FF’.
367+
let byte = self.reader.read_u8()?;
368+
if byte != 0x00 && byte != 0xFF {
369+
return Ok(Marker::from_u8(byte).unwrap());
370+
}
372371
}
373372
}
374373

@@ -539,7 +538,10 @@ impl<R: Read> Decoder<R> {
539538
}
540539
}
541540

542-
let marker = huffman.take_marker(&mut self.reader)?;
541+
let mut marker = huffman.take_marker(&mut self.reader)?;
542+
while let Some(Marker::RST(_)) = marker {
543+
marker = self.read_marker().ok();
544+
}
543545

544546
if produce_data {
545547
// Retrieve all the data from the worker thread.

src/error.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::any::Any;
21
use std::error::Error as StdError;
32
use std::fmt;
43
use std::io::Error as IoError;
5-
use std::sync::mpsc::{RecvError, SendError};
64

75
pub type Result<T> = ::std::result::Result<T, Error>;
86

@@ -41,7 +39,7 @@ pub enum Error {
4139
/// An I/O error occurred while decoding the image.
4240
Io(IoError),
4341
/// An internal error occurred while decoding the image.
44-
Internal(Box<dyn StdError>),
42+
Internal(Box<dyn StdError + Send + Sync + 'static>), //TODO: not used, can be removed with the next version bump
4543
}
4644

4745
impl fmt::Display for Error {
@@ -79,15 +77,3 @@ impl From<IoError> for Error {
7977
Error::Io(err)
8078
}
8179
}
82-
83-
impl From<RecvError> for Error {
84-
fn from(err: RecvError) -> Error {
85-
Error::Internal(Box::new(err))
86-
}
87-
}
88-
89-
impl<T: Any + Send> From<SendError<T>> for Error {
90-
fn from(err: SendError<T>) -> Error {
91-
Error::Internal(Box::new(err))
92-
}
93-
}

src/marker.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ impl Marker {
132132
0xFD => Some(JPGn(13)),
133133
0xFE => Some(COM),
134134
0xFF => None, // Fill byte
135-
_ => unreachable!(),
136135
}
137136
}
138137
}

src/worker/threaded.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ impl Worker for ThreadedWorker {
4040
Ok(ThreadedWorker { sender: tx })
4141
}
4242
fn start(&mut self, row_data: RowData) -> Result<()> {
43-
Ok(self.sender.send(WorkerMsg::Start(row_data))?)
43+
Ok(self.sender.send(WorkerMsg::Start(row_data)).expect("jpeg-decoder worker thread error"))
4444
}
4545
fn append_row(&mut self, row: (usize, Vec<i16>)) -> Result<()> {
46-
Ok(self.sender.send(WorkerMsg::AppendRow(row))?)
46+
Ok(self.sender.send(WorkerMsg::AppendRow(row)).expect("jpeg-decoder worker thread error"))
4747
}
4848
fn get_result(&mut self, index: usize) -> Result<Vec<u8>> {
4949
let (tx, rx) = mpsc::channel();
50-
self.sender.send(WorkerMsg::GetResult((index, tx)))?;
51-
Ok(rx.recv()?)
50+
self.sender.send(WorkerMsg::GetResult((index, tx))).expect("jpeg-decoder worker thread error");
51+
Ok(rx.recv().expect("jpeg-decoder worker thread error"))
5252
}
5353
}

tests/crashtest/images/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ imagetestsuite/ | The files in this directory were taken from https://
55
dc-predictor-overflow.jpg | Found by Wim Looman (@Nemo157) while fuzzing
66
derive-huffman-codes-overflow.jpg | Found by Pascal Hertleif (@killercup) while fuzzing
77
missing-sof.jpg | Found by Corey Farwell (@frewsxcv) when fuzz testing
8+
extraneous-bytes-after-sos.jpg | Scan from brother DSmobile 920DW provided by Filip Lundborg (@filipl)
Loading

0 commit comments

Comments
 (0)