Skip to content

Commit

Permalink
Fix off-by-one error in MIME pattern matching
Browse files Browse the repository at this point in the history
This adds a size to the test webp file, since the error fixed occurs
when the test object is the same length as the matched pattern, and
is not equal to the pattern.
  • Loading branch information
jongiddy committed Feb 23, 2016
1 parent 94f5d26 commit 480cb38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions components/net/mime_classifier.rs
Expand Up @@ -294,7 +294,7 @@ impl ByteMatcher {
} else if data == self.pattern {
Some(self.pattern.len())
} else {
data[..data.len() - self.pattern.len()].iter()
data[..data.len() - self.pattern.len() + 1].iter()
.position(|x| !self.leading_ignore.contains(x))
.and_then(|start|
if data[start..].iter()
Expand All @@ -316,15 +316,19 @@ impl MIMEChecker for ByteMatcher {
}

fn validate(&self) -> Result<(), String> {
if self.pattern.len() == 0 {
return Err(format!(
"Zero length pattern for {}/{}",
self.content_type.0, self.content_type.1
))
}
if self.pattern.len() != self.mask.len() {
Err(format!(
"Unequal pattern and mask length for {}/{}",
return Err(format!(
"Unequal pattern and mask length for {}/{}",
self.content_type.0, self.content_type.1
))
}
else {
Ok(())
}
Ok(())
}
}

Expand Down
Binary file modified tests/unit/net/parsable_mime/image/webp/test.webp
Binary file not shown.

0 comments on commit 480cb38

Please sign in to comment.