After upgrading Sharpcompress from 0.33.0 to 0.34.0, error when decompressing a ZipStream #591

Closed
opened 2026-01-29 22:14:14 +00:00 by claunia · 12 comments
Owner

Originally created by @hmoraes on GitHub (Sep 22, 2023).

Hello,

I have been using Sharpcompress in a file decompression flow in my project (any format supported by Sharpcompress). My implementation receives a Stream which is passed to Sharpcompress using the implementation below:

public bool Descompactar(
    Stream stream,
    string destino,
    ReaderOptions readerOptions = null,
    CancellationToken cancellationToken = default)
{
    if (stream is null)
        return false;

    if (cancellationToken.IsCancellationRequested)
        return false;

    try
    {
        var destinoDiretorioInfo = new DirectoryInfo(destino);
        if (!destinoDiretorioInfo.Exists)
            destinoDiretorioInfo.Create();

        if (stream.CanSeek)
            stream.Seek(0, SeekOrigin.Begin);

        if (readerOptions is null)
        {
            readerOptions = new ReaderOptions();
            // configuration to allow pt-br accent recognition
            readerOptions.ArchiveEncoding.Forced = Encoding.GetEncoding(850);
        }

        using var arquivo = ArchiveFactory.Open(stream, readerOptions);
        arquivo.WriteToDirectory(destinoDiretorioInfo.FullName, new() { Overwrite = true });
        return true;
    }
    catch (Exception ex)
    {
        // throws here
        return false;
    }
}

Until version 0.33.0, decompressing a Stream from a Zip file was working perfectly. When upgrading to version 0.34.0 (with ZstdSharp support) the following exception started to be thrown:

System.MissingMethodException: 'Method not found: 'Void ZstdSharp.DecompressionStream..ctor(System.IO.Stream, Int32)'.'
   at SharpCompress.Common.Zip.ZipFilePart.CreateDecompressionStream(Stream stream, ZipCompressionMethod method)
   at SharpCompress.Common.Zip.ZipFilePart.GetCompressedStream()
   at SharpCompress.Common.Zip.SeekableZipFilePart.GetCompressedStream()
   at SharpCompress.Archives.Zip.ZipArchiveEntry.OpenEntryStream()
   at SharpCompress.Archives.IArchiveEntryExtensions.WriteTo(IArchiveEntry archiveEntry, Stream streamToWriteTo)
   at SharpCompress.Archives.IArchiveEntryExtensions.<>c__DisplayClass2_0.<WriteToFile>b__0(String x, FileMode fm)
   at SharpCompress.Common.ExtractionMethods.WriteEntryToFile(IEntry entry, String destinationFileName, ExtractionOptions options, Action`2 openAndWrite)
   at SharpCompress.Archives.IArchiveEntryExtensions.WriteToFile(IArchiveEntry entry, String destinationFileName, ExtractionOptions options)
   at SharpCompress.Common.ExtractionMethods.WriteEntryToDirectory(IEntry entry, String destinationDirectory, ExtractionOptions options, Action`2 write)
   at SharpCompress.Archives.IArchiveEntryExtensions.WriteToDirectory(IArchiveEntry entry, String destinationDirectory, ExtractionOptions options)
   at SharpCompress.Archives.IArchiveExtensions.WriteToDirectory(IArchive archive, String destinationDirectory, ExtractionOptions options)
   at GestaoArquivos.CrossCutting.Helpers.ArquivoHelper.Descompactar(Stream stream, String destino, ReaderOptions readerOptions, CancellationToken cancellationToken) in ArquivoHelper.cs:line 134

image

I have some unit tests in this function in which I validate the uncompressed files from the attached Zip. The test consists of checking the decompression of files with accentuation.

teste-arquivo-compactado.zip

My project is in .Net7.0. Do I have to make any corrections to my implementation?

Originally created by @hmoraes on GitHub (Sep 22, 2023). Hello, I have been using Sharpcompress in a file decompression flow in my project (any format supported by Sharpcompress). My implementation receives a Stream which is passed to Sharpcompress using the implementation below: ``` public bool Descompactar( Stream stream, string destino, ReaderOptions readerOptions = null, CancellationToken cancellationToken = default) { if (stream is null) return false; if (cancellationToken.IsCancellationRequested) return false; try { var destinoDiretorioInfo = new DirectoryInfo(destino); if (!destinoDiretorioInfo.Exists) destinoDiretorioInfo.Create(); if (stream.CanSeek) stream.Seek(0, SeekOrigin.Begin); if (readerOptions is null) { readerOptions = new ReaderOptions(); // configuration to allow pt-br accent recognition readerOptions.ArchiveEncoding.Forced = Encoding.GetEncoding(850); } using var arquivo = ArchiveFactory.Open(stream, readerOptions); arquivo.WriteToDirectory(destinoDiretorioInfo.FullName, new() { Overwrite = true }); return true; } catch (Exception ex) { // throws here return false; } } ``` Until version 0.33.0, decompressing a Stream from a Zip file was working perfectly. When upgrading to version 0.34.0 (with ZstdSharp support) the following exception started to be thrown: ``` System.MissingMethodException: 'Method not found: 'Void ZstdSharp.DecompressionStream..ctor(System.IO.Stream, Int32)'.' at SharpCompress.Common.Zip.ZipFilePart.CreateDecompressionStream(Stream stream, ZipCompressionMethod method) at SharpCompress.Common.Zip.ZipFilePart.GetCompressedStream() at SharpCompress.Common.Zip.SeekableZipFilePart.GetCompressedStream() at SharpCompress.Archives.Zip.ZipArchiveEntry.OpenEntryStream() at SharpCompress.Archives.IArchiveEntryExtensions.WriteTo(IArchiveEntry archiveEntry, Stream streamToWriteTo) at SharpCompress.Archives.IArchiveEntryExtensions.<>c__DisplayClass2_0.<WriteToFile>b__0(String x, FileMode fm) at SharpCompress.Common.ExtractionMethods.WriteEntryToFile(IEntry entry, String destinationFileName, ExtractionOptions options, Action`2 openAndWrite) at SharpCompress.Archives.IArchiveEntryExtensions.WriteToFile(IArchiveEntry entry, String destinationFileName, ExtractionOptions options) at SharpCompress.Common.ExtractionMethods.WriteEntryToDirectory(IEntry entry, String destinationDirectory, ExtractionOptions options, Action`2 write) at SharpCompress.Archives.IArchiveEntryExtensions.WriteToDirectory(IArchiveEntry entry, String destinationDirectory, ExtractionOptions options) at SharpCompress.Archives.IArchiveExtensions.WriteToDirectory(IArchive archive, String destinationDirectory, ExtractionOptions options) at GestaoArquivos.CrossCutting.Helpers.ArquivoHelper.Descompactar(Stream stream, String destino, ReaderOptions readerOptions, CancellationToken cancellationToken) in ArquivoHelper.cs:line 134 ``` ![image](https://github.com/adamhathcock/sharpcompress/assets/550310/36eac18b-d850-4135-be0d-7c58020f6147) I have some unit tests in this function in which I validate the uncompressed files from the attached Zip. The test consists of checking the decompression of files with accentuation. [teste-arquivo-compactado.zip](https://github.com/adamhathcock/sharpcompress/files/12703312/teste-arquivo-compactado.zip) My project is in .Net7.0. Do I have to make any corrections to my implementation?
Author
Owner

@adamhathcock commented on GitHub (Sep 23, 2023):

it seems like you're missing the dependency....this should be resolved via nuget

@adamhathcock commented on GitHub (Sep 23, 2023): it seems like you're missing the dependency....this should be resolved via nuget
Author
Owner

@Sicos1977 commented on GitHub (Sep 28, 2023):

I have the latest version from nuget and have the exact same issue. I'm not missing the zstdSharp.Port dependency.

I'm on .net 4.8.1

@Sicos1977 commented on GitHub (Sep 28, 2023): I have the latest version from nuget and have the exact same issue. I'm not missing the zstdSharp.Port dependency. I'm on .net 4.8.1
Author
Owner

@Sicos1977 commented on GitHub (Sep 28, 2023):

It seems the signature has changed this year on the DecompressionStream.

When downgrading to version zstdSharp 6.0 the problem went away.

https://github.com/oleg-st/ZstdSharp/blob/master/src/ZstdSharp/DecompressionStream.cs

So I guess you need to upgrade the package version you are using.

I don't mind an older version but then at least at a dependency on the nuget package that says you need to use version 6.0

@Sicos1977 commented on GitHub (Sep 28, 2023): It seems the signature has changed this year on the DecompressionStream. When downgrading to version zstdSharp 6.0 the problem went away. https://github.com/oleg-st/ZstdSharp/blob/master/src/ZstdSharp/DecompressionStream.cs So I guess you need to upgrade the package version you are using. I don't mind an older version but then at least at a dependency on the nuget package that says you need to use version 6.0
Author
Owner

@adamhathcock commented on GitHub (Sep 28, 2023):

are you not recompiling?

@adamhathcock commented on GitHub (Sep 28, 2023): are you not recompiling?
Author
Owner

@Sicos1977 commented on GitHub (Sep 28, 2023):

How do you mean. I always recompile the code after upgrading nuget packages

Your current package on nuget just expect another signature because a few optional parameters are added to de DecompressionStream.

@Sicos1977 commented on GitHub (Sep 28, 2023): How do you mean. I always recompile the code after upgrading nuget packages Your current package on nuget just expect another signature because a few optional parameters are added to de DecompressionStream.
Author
Owner

@leandroconsiglio commented on GitHub (Sep 28, 2023):

Same problem here
image

@leandroconsiglio commented on GitHub (Sep 28, 2023): Same problem here ![image](https://github.com/adamhathcock/sharpcompress/assets/18240088/56af3116-8ab0-43a1-9d0e-66038ce8339e)
Author
Owner

@hmoraes commented on GitHub (Sep 28, 2023):

The exception is very strange because it only happens in my project. I created another ConsoleApp and implemented the same function. Worked perfectly.

I'm trying to bring usage dependencies or other attached projects to ConsoleApp, but it keeps working.

@hmoraes commented on GitHub (Sep 28, 2023): The exception is very strange because it only happens in my project. I created another ConsoleApp and implemented the same function. Worked perfectly. I'm trying to bring usage dependencies or other attached projects to ConsoleApp, but it keeps working.
Author
Owner

@adamhathcock commented on GitHub (Sep 29, 2023):

does it have to do with what your target is? maybe it should be included for everything?

@adamhathcock commented on GitHub (Sep 29, 2023): does it have to do with what your target is? maybe it should be included for everything?
Author
Owner

@rodesfl commented on GitHub (Sep 30, 2023):

I have the exact same problem, here is how I fixed:

I have two services using this library, one of them is on premise at my clients, the other is on the server. When I updated the server version (0.34.0) I began to get this error, and the reason is that I'm trying to decompress a file using .34 that was compressed using .33.

When I downgraded my server to .33 the problem was fixed, so I guess there is a backward compatibily problem there. No big deal, but it is going to be a pain to update my clients and server at the same time.

@hmoraes @Sicos1977 @leandroconsiglio

@rodesfl commented on GitHub (Sep 30, 2023): I have the exact same problem, here is how I fixed: I have two services using this library, one of them is on premise at my clients, the other is on the server. When I updated the server version (0.34.0) I began to get this error, and the reason is that **I'm trying to decompress a file using .34 that was compressed using .33**. **When I downgraded my server to .33 the problem was fixed**, so I guess there is a backward compatibily problem there. No big deal, but it is going to be a pain to update my clients and server at the same time. @hmoraes @Sicos1977 @leandroconsiglio
Author
Owner

@adamhathcock commented on GitHub (Oct 2, 2023):

I released 0.34.1 which updates the zstd assembly.

I may pull the dependency into the lib as I done with other things

https://github.com/adamhathcock/sharpcompress/releases/tag/0.34.1

@adamhathcock commented on GitHub (Oct 2, 2023): I released 0.34.1 which updates the zstd assembly. I may pull the dependency into the lib as I done with other things https://github.com/adamhathcock/sharpcompress/releases/tag/0.34.1
Author
Owner

@hmoraes commented on GitHub (Oct 2, 2023):

@rodesfl My solution contains 5 projects and the SharpCompress dependency is only installed in the base library project

@adamhathcock I tested the new version 0.34.1 and the problem was resolved. Now it's working perfectly. Thank you very much!

@hmoraes commented on GitHub (Oct 2, 2023): @rodesfl My solution contains 5 projects and the SharpCompress dependency is only installed in the base library project @adamhathcock I tested the new version 0.34.1 and the problem was resolved. Now it's working perfectly. Thank you very much!
Author
Owner

@rodesfl commented on GitHub (Oct 2, 2023):

I released 0.34.1 which updates the zstd assembly.

I may pull the dependency into the lib as I done with other things

https://github.com/adamhathcock/sharpcompress/releases/tag/0.34.1

Awesome, thank you.

@rodesfl commented on GitHub (Oct 2, 2023): > I released 0.34.1 which updates the zstd assembly. > > I may pull the dependency into the lib as I done with other things > > https://github.com/adamhathcock/sharpcompress/releases/tag/0.34.1 Awesome, thank you.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#591