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> {
85
85
// length is including itself.
86
86
let length = reader. read_u16 :: < BigEndian > ( ) ? as usize ;
87
87
88
- if length <= 2 {
88
+ if length < 2 {
89
89
return Err ( Error :: Format ( format ! ( "encountered {:?} with invalid length {}" , marker, length) ) ) ;
90
90
}
91
91
@@ -232,14 +232,18 @@ pub fn parse_sof<R: Read>(reader: &mut R, marker: Marker) -> Result<FrameInfo> {
232
232
// Section B.2.3
233
233
pub fn parse_sos < R : Read > ( reader : & mut R , frame : & FrameInfo ) -> Result < ScanInfo > {
234
234
let length = read_length ( reader, SOS ) ?;
235
+ if 0 == length {
236
+ return Err ( Error :: Format ( "zero length in SOS" . to_owned ( ) ) ) ;
237
+ }
238
+
235
239
let component_count = reader. read_u8 ( ) ?;
236
240
237
241
if component_count == 0 || component_count > 4 {
238
242
return Err ( Error :: Format ( format ! ( "invalid component count {} in scan header" , component_count) ) ) ;
239
243
}
240
244
241
245
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 ( ) ) ) ;
243
247
}
244
248
245
249
let mut component_indices = Vec :: with_capacity ( component_count as usize ) ;
You can’t perform that action at this time.
0 commit comments