Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
fix: Avoid out-of-bounds indexing
Browse files Browse the repository at this point in the history
This was found by QuickCheck.
  • Loading branch information
badboy committed May 12, 2016
1 parent c0e7b42 commit 88242ff
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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.