Permalink
Browse files

fix: Avoid out-of-bounds indexing

This was found by QuickCheck.
  • Loading branch information...
1 parent c0e7b42 commit 88242ffef3b00423572db66318becd5206880d94 @badboy committed May 12, 2016
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/compress.rs
View
@@ -140,7 +140,7 @@ pub fn compress(data: &[u8]) -> LzfResult<Vec<u8>> {
current_offset += 1;
} else {
/* one more literal byte we must copy */
- if current_offset >= out_buf_len {
+ if out_len >= out_buf_len as i32 {
return Err(LzfError::NoCompressionPossible);
}
@@ -252,3 +252,10 @@ fn test_alice_wonderland_both() {
assert_eq!(&compressed[..], &c_compressed[..]);
}
+
+#[test]
+fn quickcheck_found_bug() {
+ let inp = vec![0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 1, 1, 0, 1, 2, 0, 1, 3, 0, 1, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 1, 5, 0, 1, 6, 0, 1, 7, 0, 1, 8, 0, 1, 9, 0, 1, 10, 0, 0];
+
+ assert_eq!(LzfError::NoCompressionPossible, compress(&inp).unwrap_err());
+}

0 comments on commit 88242ff

Please sign in to comment.