@@ -232,7 +232,7 @@ impl<R: Read> Decoder<R> {
232232 Marker :: DQT => {
233233 let tables = parse_dqt ( & mut self . reader ) ?;
234234
235- for ( i, & table) in tables. into_iter ( ) . enumerate ( ) {
235+ for ( i, & table) in tables. iter ( ) . enumerate ( ) {
236236 if let Some ( table) = table {
237237 let mut unzigzagged_table = [ 0u16 ; 64 ] ;
238238
@@ -333,23 +333,22 @@ impl<R: Read> Decoder<R> {
333333 }
334334
335335 fn read_marker ( & mut self ) -> Result < Marker > {
336- // This should be an error as the JPEG spec doesn't allow extraneous data between marker segments.
337- // libjpeg allows this though and there are images in the wild utilising it, so we are
338- // forced to support this behavior.
339- // Sony Ericsson P990i is an example of a device which produce this sort of JPEGs.
340- while self . reader . read_u8 ( ) ? != 0xFF { }
341-
342- let mut byte = self . reader . read_u8 ( ) ?;
343-
344- // Section B.1.1.2
345- // "Any marker may optionally be preceded by any number of fill bytes, which are bytes assigned code X’FF’."
346- while byte == 0xFF {
347- byte = self . reader . read_u8 ( ) ?;
348- }
349-
350- match byte {
351- 0x00 => Err ( Error :: Format ( "FF 00 found where marker was expected" . to_owned ( ) ) ) ,
352- _ => Ok ( Marker :: from_u8 ( byte) . unwrap ( ) ) ,
336+ loop {
337+ // This should be an error as the JPEG spec doesn't allow extraneous data between marker segments.
338+ // libjpeg allows this though and there are images in the wild utilising it, so we are
339+ // forced to support this behavior.
340+ // Sony Ericsson P990i is an example of a device which produce this sort of JPEGs.
341+ while self . reader . read_u8 ( ) ? != 0xFF { }
342+
343+ // Section B.1.1.2
344+ // All markers are assigned two-byte codes: an X’FF’ byte followed by a
345+ // byte which is not equal to 0 or X’FF’ (see Table B.1). Any marker may
346+ // optionally be preceded by any number of fill bytes, which are bytes
347+ // assigned code X’FF’.
348+ let byte = self . reader . read_u8 ( ) ?;
349+ if byte != 0x00 && byte != 0xFF {
350+ return Ok ( Marker :: from_u8 ( byte) . unwrap ( ) ) ;
351+ }
353352 }
354353 }
355354
@@ -520,7 +519,10 @@ impl<R: Read> Decoder<R> {
520519 }
521520 }
522521
523- let marker = huffman. take_marker ( & mut self . reader ) ?;
522+ let mut marker = huffman. take_marker ( & mut self . reader ) ?;
523+ while let Some ( Marker :: RST ( _) ) = marker {
524+ marker = self . read_marker ( ) . ok ( ) ;
525+ }
524526
525527 if produce_data {
526528 // Retrieve all the data from the worker thread.
0 commit comments