Failing to Read .7z Archive (LZMA:23) #595

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

Originally created by @Aragas on GitHub (Oct 7, 2023).

I'm failing to extract this archive - "Sturgia is Norse for 1.0.2" via ArchiveFactory.Open
https://www.nexusmods.com/mountandblade2bannerlord/mods/2713?tab=files
Opening via 7z works, so the archive seems correct.
Not sure what data I can give to help - the archive is SOLID with 1 block and the method is LZMA:23

SharpCompress.Compressors.LZMA.DataErrorException: Data Error
   at SharpCompress.Compressors.LZMA.LzmaStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at SharpCompress.Compressors.LZMA.Utilites.Utils.ReadExact(Stream stream, Byte[] buffer, Int32 offset, Int32 length)
   at SharpCompress.Common.SevenZip.ArchiveReader.ReadAndDecodePackedStreams(Int64 baseOffset, IPasswordProvider pass)
   at SharpCompress.Common.SevenZip.ArchiveReader.ReadDatabase(IPasswordProvider pass)
   at SharpCompress.Archives.SevenZip.SevenZipArchive.LoadFactory(Stream stream)
   at SharpCompress.Archives.SevenZip.SevenZipArchive.LoadEntries(IEnumerable`1 volumes)
   at SharpCompress.Archives.AbstractArchive`2..ctor(ArchiveType type, SourceStream srcStream)
   at SharpCompress.Archives.SevenZip.SevenZipArchive..ctor(SourceStream srcStream)
   at SharpCompress.Archives.SevenZip.SevenZipArchive.Open(FileInfo fileInfo, ReaderOptions readerOptions)
   at SharpCompress.Factories.SevenZipFactory.Open(FileInfo fileInfo, ReaderOptions readerOptions)
   at SharpCompress.Archives.ArchiveFactory.Open(FileInfo fileInfo, ReaderOptions options)
   at SharpCompress.Archives.ArchiveFactory.Open(String filePath, ReaderOptions options)
   at ...
Originally created by @Aragas on GitHub (Oct 7, 2023). I'm failing to extract this archive - "Sturgia is Norse for 1.0.2" via `ArchiveFactory.Open` https://www.nexusmods.com/mountandblade2bannerlord/mods/2713?tab=files Opening via 7z works, so the archive seems correct. Not sure what data I can give to help - the archive is SOLID with 1 block and the method is LZMA:23 ``` SharpCompress.Compressors.LZMA.DataErrorException: Data Error at SharpCompress.Compressors.LZMA.LzmaStream.Read(Byte[] buffer, Int32 offset, Int32 count) at SharpCompress.Compressors.LZMA.Utilites.Utils.ReadExact(Stream stream, Byte[] buffer, Int32 offset, Int32 length) at SharpCompress.Common.SevenZip.ArchiveReader.ReadAndDecodePackedStreams(Int64 baseOffset, IPasswordProvider pass) at SharpCompress.Common.SevenZip.ArchiveReader.ReadDatabase(IPasswordProvider pass) at SharpCompress.Archives.SevenZip.SevenZipArchive.LoadFactory(Stream stream) at SharpCompress.Archives.SevenZip.SevenZipArchive.LoadEntries(IEnumerable`1 volumes) at SharpCompress.Archives.AbstractArchive`2..ctor(ArchiveType type, SourceStream srcStream) at SharpCompress.Archives.SevenZip.SevenZipArchive..ctor(SourceStream srcStream) at SharpCompress.Archives.SevenZip.SevenZipArchive.Open(FileInfo fileInfo, ReaderOptions readerOptions) at SharpCompress.Factories.SevenZipFactory.Open(FileInfo fileInfo, ReaderOptions readerOptions) at SharpCompress.Archives.ArchiveFactory.Open(FileInfo fileInfo, ReaderOptions options) at SharpCompress.Archives.ArchiveFactory.Open(String filePath, ReaderOptions options) at ... ```
claunia added the enhancementup for grabs labels 2026-01-29 22:14:19 +00:00
Author
Owner

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

I guess this is an enhancement as this is a LZMA type not handled

@adamhathcock commented on GitHub (Oct 8, 2023): I guess this is an enhancement as this is a LZMA type not handled
Author
Owner

@Erior commented on GitHub (Dec 7, 2023):

Have made some progress, this seems to be connected to LZMA EndOfStream marker, there are very small 7z files to test with that triggers the scenario. might take a look when I have the time.

@Erior commented on GitHub (Dec 7, 2023): Have made some progress, this seems to be connected to LZMA EndOfStream marker, there are very small 7z files to test with that triggers the scenario. might take a look when I have the time.
Author
Owner

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

I still seem to get a similar issue:

SharpCompress.Compressors.LZMA.DataErrorException: Data Error
   at SharpCompress.Compressors.LZMA.LzmaStream.DecodeChunkHeaderAsync(CancellationToken cancellationToken) in /_/src/SharpCompress/Compressors/LZMA/LzmaStream.cs:line 451
   at SharpCompress.Compressors.LZMA.LzmaStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) in /_/src/SharpCompress/Compressors/LZMA/LzmaStream.cs:line 545
   at SharpCompress.IO.ReadOnlySubStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken) in /_/src/SharpCompress/IO/ReadOnlySubStream.cs:line 127
   at System.IO.Stream.<CopyToAsync>g__Core|30_0(Stream source, Stream destination, Int32 bufferSize, CancellationToken cancellationToken)
   at ...

opening the archive manually via 7z works fine, no issues or corruption

@pjominet commented on GitHub (Jan 4, 2026): I still seem to get a similar issue: ``` SharpCompress.Compressors.LZMA.DataErrorException: Data Error at SharpCompress.Compressors.LZMA.LzmaStream.DecodeChunkHeaderAsync(CancellationToken cancellationToken) in /_/src/SharpCompress/Compressors/LZMA/LzmaStream.cs:line 451 at SharpCompress.Compressors.LZMA.LzmaStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) in /_/src/SharpCompress/Compressors/LZMA/LzmaStream.cs:line 545 at SharpCompress.IO.ReadOnlySubStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken) in /_/src/SharpCompress/IO/ReadOnlySubStream.cs:line 127 at System.IO.Stream.<CopyToAsync>g__Core|30_0(Stream source, Stream destination, Int32 bufferSize, CancellationToken cancellationToken) at ... ``` opening the archive manually via 7z works fine, no issues or corruption
Author
Owner

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

Please be more specific with code and a sample file

@adamhathcock commented on GitHub (Jan 4, 2026): Please be more specific with code and a sample file
Author
Owner

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

this was the zip (7z) used: https://www.nexusmods.com/witcher2/mods/707?tab=files
and here is the code that tries to open it:

public async Task<ModArchive> LoadModArchive(string archivePath, CancellationToken? ctx = null)
    {
        var modArchive = new ModArchive
        {
            SourcePath = archivePath
        };

        try
        {
            // create mod folder in staging directory
            modArchive.StagingPath = Path.Combine(configService.ModStagingPath, modArchive.ModName);
            Directory.CreateDirectory(modArchive.StagingPath);

            using (var archive = ArchiveFactory.Open(archivePath))
            {
                foreach (var entry in archive.Entries.Where(e => !e.IsDirectory))
                {
                    var normalizedPath = entry.Key.NormalizePath();

                    // simplified for clarity

                    await using var entryStream = await entry.OpenEntryStreamAsync(ctx ?? CancellationToken.None);
                    using var ms = new MemoryStream();
                    await entryStream.CopyToAsync(ms);
                    ms.Position = 0;

                    // Extract to file
                    var stagingPath = Path.Combine(modArchive.StagingPath, fileStagingPath);
                    Directory.CreateDirectory(Path.GetDirectoryName(stagingPath)!);
                    await using (var fileStream = File.Create(stagingPath))
                    {
                        await ms.CopyToAsync(fileStream);
                    }

                    // Create ModFile reference
                    modArchive.Files.Add(new ModFile
                    {
                        RelativePath = fileStagingPath,
                        Content = ms.ToArray()
                    });
                }
            }

            modArchive.IsLoaded = true;
        }
        catch (Exception ex)
        {
            modArchive.Error = $"Extracting archive failed: {ex.Message}";
            modArchive.IsLoaded = false;
        }

        return modArchive;
    }
@pjominet commented on GitHub (Jan 8, 2026): this was the zip (7z) used: https://www.nexusmods.com/witcher2/mods/707?tab=files and here is the code that tries to open it: ```c# public async Task<ModArchive> LoadModArchive(string archivePath, CancellationToken? ctx = null) { var modArchive = new ModArchive { SourcePath = archivePath }; try { // create mod folder in staging directory modArchive.StagingPath = Path.Combine(configService.ModStagingPath, modArchive.ModName); Directory.CreateDirectory(modArchive.StagingPath); using (var archive = ArchiveFactory.Open(archivePath)) { foreach (var entry in archive.Entries.Where(e => !e.IsDirectory)) { var normalizedPath = entry.Key.NormalizePath(); // simplified for clarity await using var entryStream = await entry.OpenEntryStreamAsync(ctx ?? CancellationToken.None); using var ms = new MemoryStream(); await entryStream.CopyToAsync(ms); ms.Position = 0; // Extract to file var stagingPath = Path.Combine(modArchive.StagingPath, fileStagingPath); Directory.CreateDirectory(Path.GetDirectoryName(stagingPath)!); await using (var fileStream = File.Create(stagingPath)) { await ms.CopyToAsync(fileStream); } // Create ModFile reference modArchive.Files.Add(new ModFile { RelativePath = fileStagingPath, Content = ms.ToArray() }); } } modArchive.IsLoaded = true; } catch (Exception ex) { modArchive.Error = $"Extracting archive failed: {ex.Message}"; modArchive.IsLoaded = false; } return modArchive; } ```
Author
Owner

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

version 0.44.0 seem to have fixed it :D

@pjominet commented on GitHub (Jan 8, 2026): version 0.44.0 seem to have fixed it :D
Author
Owner

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

Yes, it was an async issue, so go with the latest release

@Erior commented on GitHub (Jan 8, 2026): Yes, it was an async issue, so go with the latest release
Author
Owner

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

Great!

@adamhathcock commented on GitHub (Jan 8, 2026): Great!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#595