File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ fn read_length<R: Read>(reader: &mut R, marker: Marker) -> Result<usize> {
8585 // length is including itself.
8686 let length = reader. read_u16 :: < BigEndian > ( ) ? as usize ;
8787
88- if length <= 2 {
88+ if length < 2 {
8989 return Err ( Error :: Format ( format ! ( "encountered {:?} with invalid length {}" , marker, length) ) ) ;
9090 }
9191
@@ -232,14 +232,18 @@ pub fn parse_sof<R: Read>(reader: &mut R, marker: Marker) -> Result<FrameInfo> {
232232// Section B.2.3
233233pub fn parse_sos < R : Read > ( reader : & mut R , frame : & FrameInfo ) -> Result < ScanInfo > {
234234 let length = read_length ( reader, SOS ) ?;
235+ if 0 == length {
236+ return Err ( Error :: Format ( "zero length in SOS" . to_owned ( ) ) ) ;
237+ }
238+
235239 let component_count = reader. read_u8 ( ) ?;
236240
237241 if component_count == 0 || component_count > 4 {
238242 return Err ( Error :: Format ( format ! ( "invalid component count {} in scan header" , component_count) ) ) ;
239243 }
240244
241245 if length != 4 + 2 * component_count as usize {
242- return Err ( Error :: Format ( "invalid length in SOF " . to_owned ( ) ) ) ;
246+ return Err ( Error :: Format ( "invalid length in SOS " . to_owned ( ) ) ) ;
243247 }
244248
245249 let mut component_indices = Vec :: with_capacity ( component_count as usize ) ;
You can’t perform that action at this time.
0 commit comments