@@ -251,7 +251,7 @@ impl<R: Read> Decoder<R> {
251
251
Marker :: DQT => {
252
252
let tables = parse_dqt ( & mut self . reader ) ?;
253
253
254
- for ( i, & table) in tables. into_iter ( ) . enumerate ( ) {
254
+ for ( i, & table) in tables. iter ( ) . enumerate ( ) {
255
255
if let Some ( table) = table {
256
256
let mut unzigzagged_table = [ 0u16 ; 64 ] ;
257
257
@@ -352,23 +352,22 @@ impl<R: Read> Decoder<R> {
352
352
}
353
353
354
354
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
+ }
372
371
}
373
372
}
374
373
@@ -539,7 +538,10 @@ impl<R: Read> Decoder<R> {
539
538
}
540
539
}
541
540
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
+ }
543
545
544
546
if produce_data {
545
547
// Retrieve all the data from the worker thread.
0 commit comments