Skip to content

Commit e76f194

Browse files
authored
Merge pull request #94 from FauxFaux/zero-length
allow zero lengths, which matters for DHT
2 parents 2545933 + 2b11164 commit e76f194

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/parser.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff 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
233233
pub 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);

0 commit comments

Comments
 (0)