decompressing big .7z file throws error #751

Closed
opened 2026-01-29 22:16:54 +00:00 by claunia · 8 comments
Owner

Originally created by @DevOnBike on GitHub (Dec 24, 2025).

Originally assigned to: @adamhathcock, @Copilot on GitHub.

lib version 0.42.1
under .net 10

code:

public class SharpCompressExtractor : IArchiveExtractor
{
    public async Task<IReadOnlyCollection<FileInfo>> ExtractAsync(
        string archivePath,
        string destinationDirectory,
        CancellationToken token)
    {
        if (!File.Exists(archivePath))
        {
            throw new FileNotFoundException($"Nie znaleziono archiwum: {archivePath}");
        }

        var extractedFiles = new List<FileInfo>();

        using var archive = ArchiveFactory.Open(archivePath);

        foreach (var entry in archive.Entries)
        {
            if (entry.IsDirectory)
            {
                continue;
            }

            token.ThrowIfCancellationRequested();

            var targetPath = Path.Combine(destinationDirectory, entry.Key);

            var targetDir = Path.GetDirectoryName(targetPath);

            if (!string.IsNullOrEmpty(targetDir) && !Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }

            using var sourceStream = await entry.OpenEntryStreamAsync(token);

            var fileOptions = new FileStreamOptions
            {
                Mode = FileMode.Create,
                Access = FileAccess.Write,
                Share = FileShare.None,
                BufferSize = 1_024 * 1_024,
                Options = FileOptions.Asynchronous
            };

            await using var targetStream = new FileStream(targetPath, fileOptions);

            await sourceStream.CopyToAsync(targetStream, token);

            var fileInfo = new FileInfo(targetPath);

            extractedFiles.Add(fileInfo);
        }

        return extractedFiles;
    }
}

usage

            try
            {
                var files = await fileExtractor.ExtractAsync(
    "C:\\whitelist\\20251223.7z",
    "c:/whitelist/out",
    CancellationToken.None);
            }
            catch (Exception ex)
            {
                
            }

Data Error

at SharpCompress.Compressors.LZMA.LzmaStream.d__52.MoveNext()
at SharpCompress.Compressors.LZMA.LzmaStream.d__56.MoveNext()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at SharpCompress.IO.ReadOnlySubStream.d__24.MoveNext()
at System.IO.Stream.<g__Core|30_0>d.MoveNext()
at SharpCompressExtractor.d__0.MoveNext() in SharpCompressExtractor.cs

file : probably any from https://www.podatki.gov.pl/narzedzia/white-list/

but for sure exist for this url: https://plikplaski.mf.gov.pl/pliki//20251223.7z

this file perfectly uncompress under win11 using native extractor or 7zip manager

Originally created by @DevOnBike on GitHub (Dec 24, 2025). Originally assigned to: @adamhathcock, @Copilot on GitHub. lib version 0.42.1 under .net 10 code: ``` public class SharpCompressExtractor : IArchiveExtractor { public async Task<IReadOnlyCollection<FileInfo>> ExtractAsync( string archivePath, string destinationDirectory, CancellationToken token) { if (!File.Exists(archivePath)) { throw new FileNotFoundException($"Nie znaleziono archiwum: {archivePath}"); } var extractedFiles = new List<FileInfo>(); using var archive = ArchiveFactory.Open(archivePath); foreach (var entry in archive.Entries) { if (entry.IsDirectory) { continue; } token.ThrowIfCancellationRequested(); var targetPath = Path.Combine(destinationDirectory, entry.Key); var targetDir = Path.GetDirectoryName(targetPath); if (!string.IsNullOrEmpty(targetDir) && !Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } using var sourceStream = await entry.OpenEntryStreamAsync(token); var fileOptions = new FileStreamOptions { Mode = FileMode.Create, Access = FileAccess.Write, Share = FileShare.None, BufferSize = 1_024 * 1_024, Options = FileOptions.Asynchronous }; await using var targetStream = new FileStream(targetPath, fileOptions); await sourceStream.CopyToAsync(targetStream, token); var fileInfo = new FileInfo(targetPath); extractedFiles.Add(fileInfo); } return extractedFiles; } } ``` usage ``` try { var files = await fileExtractor.ExtractAsync( "C:\\whitelist\\20251223.7z", "c:/whitelist/out", CancellationToken.None); } catch (Exception ex) { } ``` Data Error at SharpCompress.Compressors.LZMA.LzmaStream.<DecodeChunkHeaderAsync>d__52.MoveNext() at SharpCompress.Compressors.LZMA.LzmaStream.<ReadAsync>d__56.MoveNext() at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult() at SharpCompress.IO.ReadOnlySubStream.<ReadAsync>d__24.MoveNext() at System.IO.Stream.<<CopyToAsync>g__Core|30_0>d.MoveNext() at SharpCompressExtractor.<ExtractAsync>d__0.MoveNext() in SharpCompressExtractor.cs file : probably any from https://www.podatki.gov.pl/narzedzia/white-list/ but for sure exist for this url: https://plikplaski.mf.gov.pl/pliki//20251223.7z this file perfectly uncompress under win11 using native extractor or 7zip manager
claunia added the bug label 2026-01-29 22:16:54 +00:00
Author
Owner

@Camble commented on GitHub (Dec 26, 2025):

Also experiencing this with my 7z tests after updating to v0.42.x
v0.41.0 is fine

@Camble commented on GitHub (Dec 26, 2025): Also experiencing this with my 7z tests after updating to v0.42.x v0.41.0 is fine
Author
Owner

@adamhathcock commented on GitHub (Dec 26, 2025):

Sounds like the fix I did for https://github.com/adamhathcock/sharpcompress/pull/1081

I can validate next week though.

@adamhathcock commented on GitHub (Dec 26, 2025): Sounds like the fix I did for https://github.com/adamhathcock/sharpcompress/pull/1081 I can validate next week though.
Author
Owner

@DevOnBike commented on GitHub (Jan 4, 2026):

Sounds like the fix I did for #1081

I can validate next week though.

nope, still same exception now in 0.43.0

@DevOnBike commented on GitHub (Jan 4, 2026): > Sounds like the fix I did for [#1081](https://github.com/adamhathcock/sharpcompress/pull/1081) > > I can validate next week though. nope, still same exception now in 0.43.0
Author
Owner

@adamhathcock commented on GitHub (Jan 6, 2026):

You're right....testing this myself the async path is broken. However, the sync path works.

If you change CopyToAsync to CopytTo then it works for me

gonna look at a real fix though

@adamhathcock commented on GitHub (Jan 6, 2026): You're right....testing this myself the async path is broken. However, the sync path works. If you change `CopyToAsync` to `CopytTo` then it works for me gonna look at a real fix though
Author
Owner

@DevOnBike commented on GitHub (Jan 6, 2026):

You're right....testing this myself the async path is broken. However, the sync path works.

If you change CopyToAsync to CopytTo then it works for me

gonna look at a real fix though

I think that current trend is to use async methods most of the time if logic is IO-bound.
So let me wait for permanet fix for async version.

@DevOnBike commented on GitHub (Jan 6, 2026): > You're right....testing this myself the async path is broken. However, the sync path works. > > If you change `CopyToAsync` to `CopytTo` then it works for me > > gonna look at a real fix though I think that current trend is to use async methods most of the time if logic is IO-bound. So let me wait for permanet fix for async version.
Author
Owner

@adamhathcock commented on GitHub (Jan 7, 2026):

Try https://www.nuget.org/packages/SharpCompress/0.44.0-beta.40

@adamhathcock commented on GitHub (Jan 7, 2026): Try https://www.nuget.org/packages/SharpCompress/0.44.0-beta.40
Author
Owner

@DevOnBike commented on GitHub (Jan 7, 2026):

Try https://www.nuget.org/packages/SharpCompress/0.44.0-beta.40

works like a charm on 0.44.0-beta.40.

So please publish it as normal package (not beta).
Thanks a lot.

@DevOnBike commented on GitHub (Jan 7, 2026): > Try https://www.nuget.org/packages/SharpCompress/0.44.0-beta.40 works like a charm on 0.44.0-beta.40. So please publish it as normal package (not beta). Thanks a lot.
Author
Owner

@DevOnBike commented on GitHub (Jan 8, 2026):

yup, works also great in final v0.44.

Thank u, and have a good day :)

@DevOnBike commented on GitHub (Jan 8, 2026): yup, works also great in final v0.44. Thank u, and have a good day :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#751