File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 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> {
612612 }
613613
614614 /// 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()`
615617 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+ }
617621
618622 if self . is_animated ( ) {
619623 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> {
787787 let value = self . peek ( num) as u32 ;
788788 self . consume ( num) ?;
789789
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+ } )
794794 }
795795}
796796
You can’t perform that action at this time.
0 commit comments