Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Small dict leads to panic #133

Merged
merged 1 commit into from Jun 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/block/compress.rs
Expand Up @@ -662,10 +662,13 @@ pub fn compress_into_with_dict(
fn compress_into_vec_with_dict<const USE_DICT: bool>(
input: &[u8],
prepend_size: bool,
dict_data: &[u8],
mut dict_data: &[u8],
) -> Vec<u8> {
let prepend_size_num_bytes = if prepend_size { 4 } else { 0 };
let max_compressed_size = get_maximum_output_size(input.len()) + prepend_size_num_bytes;
if dict_data.len() <= 3 {
dict_data = b"";
}
#[cfg(feature = "safe-encode")]
let mut compressed = {
let mut compressed: Vec<u8> = vec![0u8; max_compressed_size];
Expand Down Expand Up @@ -877,6 +880,15 @@ mod tests {
assert_eq!(input, uncompressed);
}

#[test]
fn test_dict_no_panic() {
let input: &[u8] = &[
10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 10, 12, 14, 16, 18, 10, 12, 14, 16, 18,
];
let dict = &[10, 12, 14];
let _compressed = compress_with_dict(input, dict);
}

#[test]
fn test_dict_match_crossing() {
let input: &[u8] = &[
Expand Down