Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix correctness issues for detectors #66

Merged
merged 2 commits into from
Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/matchers/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ fn msooxml(buf: &[u8]) -> Option<DocType> {
// skip to the second local file header
// since some documents include a 520-byte extra field following the file
// header, we need to scan for the next header
let mut start_offset = (u32::from_le_bytes(buf[18..22].try_into().unwrap()) + 49) as usize;
let mut start_offset = match u32::from_le_bytes(buf[18..22].try_into().unwrap()).checked_add(49)
Copy link
Contributor Author

@deuill deuill Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a file (generated by fuzz tests) that replicates this: overflow.docx

{
Some(int) => int as usize,
None => return None,
};

let idx = search(buf, start_offset, 6000)?;

// now skip to the *third* local file header; again, we need to scan due to a
Expand Down
2 changes: 1 addition & 1 deletion src/matchers/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn is_webp(buf: &[u8]) -> bool {

/// Returns whether a buffer is Canon CR2 image data.
pub fn is_cr2(buf: &[u8]) -> bool {
buf.len() > 9
buf.len() > 10
&& ((buf[0] == 0x49 && buf[1] == 0x49 && buf[2] == 0x2A && buf[3] == 0x0)
|| (buf[0] == 0x4D && buf[1] == 0x4D && buf[2] == 0x0 && buf[3] == 0x2A))
&& buf[8] == 0x43
Expand Down