IEntry.Crc returns a negative number #501

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

Originally created by @ghost on GitHub (Feb 26, 2022).

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?

Originally created by @ghost on GitHub (Feb 26, 2022). 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**?
Author
Owner

@Nanook commented on GitHub (Jul 15, 2022):

I've fixed this and will submit a fix.

@Nanook commented on GitHub (Jul 15, 2022): I've fixed this and will submit a fix.
Author
Owner

@ghost commented on GitHub (Nov 19, 2022):

@Nanook Thank you very much.

@ghost commented on GitHub (Nov 19, 2022): @Nanook Thank you very much.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#501