rust-lang / flate2-rs

DEFLATE, gzip, and zlib bindings for Rust
https://docs.rs/flate2
Apache License 2.0
862 stars 159 forks source link

Zlib succes while miniz_oxide fails #389

Closed catenacyber closed 6 months ago

catenacyber commented 6 months ago

Using code

use flate2::read::DeflateDecoder;
use std::io::prelude::*;

fn main() {
    let mut v1 = Vec::new();
    v1.extend_from_slice(&[0xf2, 0x48, 0xcd, 0xc9, 0xc9, 0x07, 0x00]);
    v1.extend_from_slice(&[0, 0, 0xFF, 0xFF]);
    let mut d = DeflateDecoder::new(&v1[..]);
    let mut s = String::new();
    d.read_to_string(&mut s).unwrap();
    println!("{}", s);
}

And Cargo.toml

[dependencies]
flate2 = { version = "1.0.28", default-features = true }

panicks

thread 'main' panicked at src/main.rs:10:30:
called `Result::unwrap()` on an `Err` value: Custom { kind: InvalidInput, error: "corrupt deflate stream" }

While Cargo.toml

[dependencies]
flate2 = { version = "1.0.28", features = ["zlib"], default-features = false }

succeeds in printing Hello

@alexcrichton this example comes from https://datatracker.ietf.org/doc/html/rfc7692#section-7.2.3.1

catenacyber commented 6 months ago

One fix may be in inflate_loop

Instead of

if (status as i32) < 0 {
            return Err(MZError::Data);
        }

add a check before like

        if (status == TINFLStatus::FailedCannotMakeProgress) && orig_in_len == 0 {
            return Err(MZError::Buf);
        }
Byron commented 6 months ago

Thanks for bringing this up!

To me it seems that rather than making this specific case work by adjusting inflate_loop, miniz_oxide should be changed to report results similarly to zlib.

If you agree, this issue could be closed in favour of a similar one over at miniz_oxide. Maybe I am missing something though.

catenacyber commented 6 months ago

miniz_oxide should be changed to report results similarly to zlib.

I agree.

Maybe I am missing something though.

Maybe I am missing something as well (like I should not use a Vec but another structure)

If you agree, this issue could be closed in favour of a similar one over at miniz_oxide.

Did you open one there already ? Or should I (next year) ?

Byron commented 6 months ago

Did you open one there already ? Or should I (next year) ?

I'd be grateful if you would open the issue and manage it whenever you get the chance. Thanks a lot!

catenacyber commented 6 months ago

Closing in favor of https://github.com/Frommi/miniz_oxide/issues/143