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

Make decompressed data from decompress_to_vec accessible on failure #113

Closed
RazrFalcon opened this issue Jan 20, 2022 · 9 comments
Closed

Comments

@RazrFalcon
Copy link

RazrFalcon commented Jan 20, 2022

Running this code with this file (decompress zip first).

miniz_oxide::inflate::decompress_to_vec_zlib(input)

produces the FailedCannotMakeProgress error.

Based on the header, it seems to be a zlib-compressed data and I have a 3rd-party app that opens it successfully.

Is it a miniz_oxide bug or data is somehow malformed?

miniz_oxide: 0.5.1

@oyvindln
Copy link
Collaborator

oyvindln commented Jan 23, 2022

From what I can see it's incompletely compressed data, it doesn't seem like the last block is indicated to be the final one. The simple decompression methods (decompress_to_vec_xx) do not have a way to recover data compressed so far if there is a failure at some point, you would need to use the lower level streaming decompression (optionally via flate2).

When testing other tools that handle raw zlib data, zlib-flate from qpdf dumps out about a 4.1 mb file (which is mostly zeroes but with a few FF bytes occasionally), while pigz gives pigz: skipping: data.zz: corrupted -- incomplete deflate data (which indicates Z_BUF_ERROR from zlib). Not sure what the file is supposed to be, it seems a bit odd in general.

@RazrFalcon
Copy link
Author

Can you clarify how can I handle it correctly using low-level API?

Let's say I have something like:

fn decode(input: &[u8], buf: &mut [u8]) -> Result<(), Error> {
    use miniz_oxide::inflate::core::inflate_flags;

    let flags =
          inflate_flags::TINFL_FLAG_PARSE_ZLIB_HEADER
        | inflate_flags::TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF;

    let mut decomp = Box::<miniz_oxide::inflate::core::DecompressorOxide>::default();

    let (status, _, _) = miniz_oxide::inflate::core::decompress(&mut decomp, input, buf, 0, flags);
    dbg!(status); // FailedCannotMakeProgress
    Ok(())
}

How can I recover all the data using this code? Or should I use flate2 to begin with?

Sadly, I cannot clarify what this data is from. It's an image, so having a lot of zero bytes is fine. All I can say that this data is valid (in the application sense, and not zlib one) and there are multiple proprietary apps that handle it perfectly. Therefore I'm trying to understand how can I process it too.

@RazrFalcon
Copy link
Author

Hi again. I've tried using flate2 but it also fails. Any suggestion about how it can be solved?

@RazrFalcon
Copy link
Author

flate2 with zlib backend also fails.

@RazrFalcon
Copy link
Author

It seems like in this particular case the bytes_written (the last value in decompress() return tuple) is exactly the same as I need. Meaning the decoder read all the data I want and I can simply ignore FailedCannotMakeProgress error.

Feel free to close this issue if this is not something that can be fixed on the library side.

@oyvindln
Copy link
Collaborator

Sorry completely forgot about this one, but yeah, if you use e.g flate2 or the low level streaming decompression the workaround is to decode until there is no more data to input and you have extracted all the currently decompressed data and then ignore the error.

@oyvindln oyvindln changed the title Getting the FailedCannotMakeProgress error on a specific data Make decompressed data from decompress_to_vec accessible on failure May 30, 2022
@oyvindln
Copy link
Collaborator

Outputting the data that has been decompressed is something that could be changed for this function, though it would be an API break, so would have to wait until a future version if it's relevant.

@oyvindln
Copy link
Collaborator

Can add this together with making alloc optional in the next release since that needs a version bump anyhow.

@oyvindln
Copy link
Collaborator

Fixed in 8179633

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants