Skip to content

Uncompressing .gz and .bz2 files when using SevenZipSharpLib with a 7z.dll of version 16.04 or greater. #6

@CraigScape

Description

@CraigScape

I ran into an issue uncompressing .gz and .bz2 files when using SevenZipSharpLib with a 7z.dll of version 16.04 or greater. These files would uncompress just fine using 7z.dll version 9.20.

After some time debugging the issue I found that the ArchiveExtractCallback.SetTotal() function is not being called when using the newer 7z.dll.

This results in _bytesCount being 0 when ArchiveExtractCallback.IntEventArgsHandler() is called. This results in a divide by zero error which the user sees as "The execution has failed due to the bug in the SevenZipSharp.".

I was able to work around this issue with the following code change in ArchiveExtractCallback.IntEventArgsHandler():

		FROM:
        var pold = (int)((_bytesWrittenOld * 100) / _bytesCount);
        _bytesWritten += e.Value;
        var pnow = (int)((_bytesWritten * 100) / _bytesCount);

		TO:

        var pold = (int)((_bytesWrittenOld * 100) / Math.Max(_bytesCount, 1));
        _bytesWritten += e.Value;
        var pnow = (int)((_bytesWritten * 100) / Math.Max(_bytesCount, 1));

This only fixes the divide by zero error, the real fix would require properly getting the uncompressed file size prior to the extraction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions