QPACK: prevent substraction underflow in VAS
@@ -97,7 +97,7 @@ impl VirtualAddressSpace {
}
pub fn relative(&self, index: RelativeIndex) -> Result<usize, Error> {
- if self.delta == 0 || self.inserted - index <= self.dropped {
+ if self.inserted < index || self.delta == 0 || self.inserted - index <= self.dropped {
Err(Error::BadRelativeIndex(index))
} else {
Ok(self.inserted - self.dropped - index - 1)
@@ -152,6 +152,13 @@ mod tests {
assert_eq!(res, Err(Error::BadRelativeIndex(0)));
}
+ #[test]
+ fn test_relative_underflow_protected() {
+ let mut vas = VirtualAddressSpace::default();
+ vas.add();
+ assert_eq!(vas.relative(2), Err(Error::BadRelativeIndex(2)));
+ }
+
proptest! {
#[test]
fn test_first_insertion_without_drop(
