Skip to content

Commit

Permalink
Fix potential capacity overflow when encoding with fixed blocks
Browse files Browse the repository at this point in the history
Currently, this crate always tries to use dynamic DEFLATE blocks, so the
codepath for static blocks is mostly unused. I've fixed it to use static
blocks in a working copy instead, and discovered that empty files, where
instart == inend, may trigger a bad allocation in that codepath.
  • Loading branch information
AlexTMjugador committed Sep 7, 2022
1 parent fcfb76c commit d4eeb23
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/squeeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! solution.

use log::{debug, trace};
use std::{cmp, f32, f64};
use std::{cmp, f64};

use crate::cache::Cache;
use crate::deflate::{calculate_block_size, BlockType};
Expand Down Expand Up @@ -447,7 +447,7 @@ pub fn lz77_optimal_fixed<C>(
s.blockstart = instart;
s.blockend = inend;
let mut h = ZopfliHash::new();
let mut costs = Vec::with_capacity(inend - instart - 1);
let mut costs = Vec::with_capacity(inend - instart);
lz77_optimal_run(
s,
in_data,
Expand Down

0 comments on commit d4eeb23

Please sign in to comment.