mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Fix off-by-one error in MIME pattern matching
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.
This commit is contained in:
parent
94f5d26131
commit
480cb385fc
2 changed files with 10 additions and 6 deletions
|
@ -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()
|
||||
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue