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

Duplicating file suffix causes panic: "entered unreachable code" #431

Open
k4yt3x opened this issue Jun 3, 2023 · 2 comments · May be fixed by #432
Open

Duplicating file suffix causes panic: "entered unreachable code" #431

k4yt3x opened this issue Jun 3, 2023 · 2 comments · May be fixed by #432
Labels
bug Something isn't working

Comments

@k4yt3x
Copy link

k4yt3x commented Jun 3, 2023

Version

0.4.1

Description

I came a cross this panic when I was trying to decompress a ZIP file with two .zip suffixes. It's easy to reproduce:

image

Current Behavior

Decompressing a file like test.zip.zip with two suffixes causes the program to panic.

Expected Behavior

The program should decompress the file normally and guess the file's type using the last suffix.

Additional Information

No response

@k4yt3x k4yt3x added the bug Something isn't working label Jun 3, 2023
@vrmiguel
Copy link
Member

vrmiguel commented Jun 3, 2023

Hey @k4yt3x, thanks a lot for the report!

@vrmiguel
Copy link
Member

vrmiguel commented Jun 3, 2023

Panic happens here:

Tar | Zip => unreachable!(),

There's not zip::read::Decoder or something that would impl Read from the zip crate, as far as I know

One thing we could do is do this instead

    let chain_reader_decoder = |format: &CompressionFormat, decoder: Box<dyn Read>| -> crate::Result<Box<dyn Read>> {
        let decoder: Box<dyn Read> = match format {
            Gzip => Box::new(flate2::read::GzDecoder::new(decoder)),
            Bzip => Box::new(bzip2::read::BzDecoder::new(decoder)),
            Lz4 => Box::new(lzzzz::lz4f::ReadDecompressor::new(decoder)?),
            Lzma => Box::new(xz2::read::XzDecoder::new(decoder)),
            Snappy => Box::new(snap::read::FrameDecoder::new(decoder)),
            Zstd => Box::new(zstd::stream::Decoder::new(decoder)?),
            Tar | Zip => decoder, // Return the decoder itself
        };
        Ok(decoder)
    };

Doing this, if passed in something like file.tar.zip or file.zip.zip, we'd unpack the outer compression, save file.tar | file.zip and finish

The user could then re-run ouch on the resulting file

@marcospb19 @figsoda I opened the PR for the change above, am open to suggestions

@vrmiguel vrmiguel linked a pull request Jun 3, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants