Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
header: Check dht length is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
etemesi254 committed Jun 20, 2022
1 parent c657cf0 commit a417663
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ where
)?);
}
}
};
if dht_length > 0 {
return Err(DecodeErrors::HuffmanDecode(format!("Bogus Huffman table definition")));
}
if dht_length > 0
{
return Err(DecodeErrors::HuffmanDecode(format!(
"Bogus Huffman table definition"
)));
}
Ok(())
}
Expand Down Expand Up @@ -486,21 +489,22 @@ pub(crate) fn parse_app<R>(
where
R: BufRead + Read,
{
let length = read_u16_be(buf)?.checked_sub(2)
let length = read_u16_be(buf)?
.checked_sub(2)
.ok_or(DecodeErrors::Format(format!(
"Invalid APP0 length. Length should be greater than 2"
)))?;


let mut bytes_read = 0;
match marker
{
Marker::APP(0) =>
{
if length !=14{
warn!("Incorrect length of APP0 ,{}, should be 14",length);
if length != 14
{
warn!("Incorrect length of APP0 ,{}, should be 14", length);
}
// Don't handle APP0 as of now
// Don't handle APP0 as of now
buf.consume(length as usize);
}
Marker::APP(1) =>
Expand Down

0 comments on commit a417663

Please sign in to comment.