@@ -333,23 +333,22 @@ impl<R: Read> Decoder<R> {
333
333
}
334
334
335
335
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
+ }
353
352
}
354
353
}
355
354
@@ -520,7 +519,10 @@ impl<R: Read> Decoder<R> {
520
519
}
521
520
}
522
521
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
+ }
524
526
525
527
if produce_data {
526
528
// Retrieve all the data from the worker thread.
0 commit comments