rust-brotli icon indicating copy to clipboard operation
rust-brotli copied to clipboard

Multiple panics caused by malformed inputs

Open lizhuohua opened this issue 4 years ago • 0 comments

Multiple runtime panics can be triggerred by constructing malformed data structures or function arguments. I believe the API design can be improve the get rid of these problems.

Examples:

use brotli::enc::command::BrotliDistanceParams;
use brotli::enc::command::Command;

fn main() {
    let mut command = Command::default();
    command.dist_prefix_ = 1000;
    let params = BrotliDistanceParams {
        distance_postfix_bits: 40,
        num_direct_distance_codes: 0,
        alphabet_size: 0,
        max_distance: 0,
    };
    let _ = brotli::enc::command::CommandRestoreDistanceCode(&command, &params);
}
use brotli::enc::command::PrefixEncodeCopyDistance;

fn main() {
    let mut code = 0;
    let mut extra_bits = 0;
    PrefixEncodeCopyDistance(100, 0, 100, &mut code, &mut extra_bits);
}
use brotli::enc::brotli_bit_stream::BrotliBuildAndStoreHuffmanTreeFast;
use brotli::enc::writer::StandardAlloc;
fn main() {
    let mut alloc = StandardAlloc::default();
    BrotliBuildAndStoreHuffmanTreeFast(
        &mut alloc,
        &[0],
        0,
        0,
        &mut [0],
        &mut [0],
        &mut 99999,
        &mut [0],
    );
}

lizhuohua avatar Apr 20 '21 11:04 lizhuohua