File tree 2 files changed +9
-5
lines changed
2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -612,8 +612,12 @@ impl<R: BufRead + Seek> WebPDecoder<R> {
612
612
}
613
613
614
614
/// Returns the raw bytes of the image. For animated images, this is the first frame.
615
+ ///
616
+ /// Fails with `ImageTooLarge` if `buf` has length different than `output_buffer_size()`
615
617
pub fn read_image ( & mut self , buf : & mut [ u8 ] ) -> Result < ( ) , DecodingError > {
616
- assert_eq ! ( Some ( buf. len( ) ) , self . output_buffer_size( ) ) ;
618
+ if Some ( buf. len ( ) ) != self . output_buffer_size ( ) {
619
+ return Err ( DecodingError :: ImageTooLarge ) ;
620
+ }
617
621
618
622
if self . is_animated ( ) {
619
623
let saved = std:: mem:: take ( & mut self . animation ) ;
Original file line number Diff line number Diff line change @@ -787,10 +787,10 @@ impl<R: BufRead> BitReader<R> {
787
787
let value = self . peek ( num) as u32 ;
788
788
self . consume ( num) ?;
789
789
790
- match value. try_into ( ) {
791
- Ok ( value ) => Ok ( value ) ,
792
- Err ( _ ) => unreachable ! ( "Value too large to fit in type" ) ,
793
- }
790
+ value. try_into ( ) . map_err ( |_| {
791
+ debug_assert ! ( false , "Value too large to fit in type" ) ;
792
+ DecodingError :: BitStreamError
793
+ } )
794
794
}
795
795
}
796
796
You can’t perform that action at this time.
0 commit comments