@@ -2,7 +2,7 @@ use byteorder_lite::{LittleEndian, ReadBytesExt};
2
2
use quick_error:: quick_error;
3
3
4
4
use std:: collections:: HashMap ;
5
- use std:: io:: { self , BufRead , BufReader , Cursor , Read , Seek } ;
5
+ use std:: io:: { self , BufRead , Cursor , Read , Seek } ;
6
6
use std:: num:: NonZeroU16 ;
7
7
use std:: ops:: Range ;
8
8
@@ -385,15 +385,8 @@ impl<R: BufRead + Seek> WebPDecoder<R> {
385
385
let max_position = position + riff_size. saturating_sub ( 12 ) ;
386
386
self . r . seek ( io:: SeekFrom :: Start ( position) ) ?;
387
387
388
- // Resist denial of service attacks by using a BufReader. In most images there
389
- // should be a very small number of chunks. However, nothing prevents a malicious
390
- // image from having an extremely large number of "unknown" chunks. Issuing
391
- // millions of reads and seeks against the underlying reader might be very
392
- // expensive.
393
- let mut reader = BufReader :: with_capacity ( 64 << 10 , & mut self . r ) ;
394
-
395
388
while position < max_position {
396
- match read_chunk_header ( & mut reader ) {
389
+ match read_chunk_header ( & mut self . r ) {
397
390
Ok ( ( chunk, chunk_size, chunk_size_rounded) ) => {
398
391
let range = position + 8 ..position + 8 + chunk_size;
399
392
position += 8 + chunk_size_rounded;
@@ -408,8 +401,8 @@ impl<R: BufRead + Seek> WebPDecoder<R> {
408
401
return Err ( DecodingError :: InvalidChunkSize ) ;
409
402
}
410
403
411
- reader . seek_relative ( 12 ) ?;
412
- let duration = reader . read_u32 :: < LittleEndian > ( ) ? & 0xffffff ;
404
+ self . r . seek_relative ( 12 ) ?;
405
+ let duration = self . r . read_u32 :: < LittleEndian > ( ) ? & 0xffffff ;
413
406
self . loop_duration =
414
407
self . loop_duration . wrapping_add ( u64:: from ( duration) ) ;
415
408
@@ -419,19 +412,19 @@ impl<R: BufRead + Seek> WebPDecoder<R> {
419
412
// and the spec says that lossless images SHOULD NOT contain ALPH
420
413
// chunks, so we treat both as indicators of lossy images.
421
414
if !self . is_lossy {
422
- let ( subchunk, ..) = read_chunk_header ( & mut reader ) ?;
415
+ let ( subchunk, ..) = read_chunk_header ( & mut self . r ) ?;
423
416
if let WebPRiffChunk :: VP8 | WebPRiffChunk :: ALPH = subchunk {
424
417
self . is_lossy = true ;
425
418
}
426
- reader . seek_relative ( chunk_size_rounded as i64 - 24 ) ?;
419
+ self . r . seek_relative ( chunk_size_rounded as i64 - 24 ) ?;
427
420
} else {
428
- reader . seek_relative ( chunk_size_rounded as i64 - 16 ) ?;
421
+ self . r . seek_relative ( chunk_size_rounded as i64 - 16 ) ?;
429
422
}
430
423
431
424
continue ;
432
425
}
433
426
434
- reader . seek_relative ( chunk_size_rounded as i64 ) ?;
427
+ self . r . seek_relative ( chunk_size_rounded as i64 ) ?;
435
428
}
436
429
Err ( DecodingError :: IoError ( e) )
437
430
if e. kind ( ) == io:: ErrorKind :: UnexpectedEof =>
@@ -884,13 +877,13 @@ pub(crate) fn range_reader<R: BufRead + Seek>(
884
877
Ok ( r. take ( range. end - range. start ) )
885
878
}
886
879
887
- pub ( crate ) fn read_fourcc < R : Read > ( mut r : R ) -> Result < WebPRiffChunk , DecodingError > {
880
+ pub ( crate ) fn read_fourcc < R : BufRead > ( mut r : R ) -> Result < WebPRiffChunk , DecodingError > {
888
881
let mut chunk_fourcc = [ 0 ; 4 ] ;
889
882
r. read_exact ( & mut chunk_fourcc) ?;
890
883
Ok ( WebPRiffChunk :: from_fourcc ( chunk_fourcc) )
891
884
}
892
885
893
- pub ( crate ) fn read_chunk_header < R : Read > (
886
+ pub ( crate ) fn read_chunk_header < R : BufRead > (
894
887
mut r : R ,
895
888
) -> Result < ( WebPRiffChunk , u64 , u64 ) , DecodingError > {
896
889
let chunk = read_fourcc ( & mut r) ?;
0 commit comments