sharpcompress icon indicating copy to clipboard operation
sharpcompress copied to clipboard

IEntry.Crc returns a negative number

Open roland5572 opened this issue 4 years ago • 1 comments

IEntry.Crc Property returns a negative number (eg: -1626075223).

When loading some .gz files, the CRC property will return a negative number. I'm not sure if negative numbers are currently the best solution for sharpcompress. But while converting this CRC to a string, an error occurs.

Test Code: C# / .net 6.0 / Visual Studio 2022

using SharpCompress.Archives;

var filePath = @"D:\001\001.gz";

using var stream = File.OpenRead(filePath);
var archive = ArchiveFactory.Open(stream);

foreach (var p in archive.Entries)
{
    var data = p.Crc;

    var text = data.ToString("X");
    Console.WriteLine(text);
}

Test Result:

FFFFFFFFD8BF5DCD

String conversion has extra "FFFFFFFF" when CRC is negative number. There is a detailed explanation about this part on stackoverflow.

https://stackoverflow.com/questions/32940417/unsigned-crc-32-for-python-to-match-javas-crc-32

Do you think it is necessary to normalize all CRCs to positive integers?

roland5572 avatar Feb 26 '22 03:02 roland5572

I've fixed this and will submit a fix.

Nanook avatar Jul 15 '22 18:07 Nanook

@Nanook Thank you very much.

ghost avatar Nov 19 '22 15:11 ghost