SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

problem with crc

Last post 02-23-2007 10:04 PM by CZahrobsky. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 02-19-2007 11:20 AM

    • A22
    • Not Ranked
    • Joined on 02-16-2007
    • Posts 4

    problem with crc

    I've created test folder with few empty files. size of each file = 0 bytes, names variant: russian and latin, while zipping files to archive i found a problem with crc cheching: ZipEntry.Name = "новый файл.txt", crc = 3809153438. Such crc is more than max acceptable value for Int32, so '(int)crc' throwed an exception and zip process failed.

    I wasn't able to fix this problem with simple changing int32->uint32 because of trouble in reading crc
  • 02-19-2007 11:21 AM In reply to

    • A22
    • Not Ranked
    • Joined on 02-16-2007
    • Posts 4

    Re: problem with crc

    Sorry, size of those problem file was 6 bytes, text file filled with few latin symbols
  • 02-19-2007 2:35 PM In reply to

    • A22
    • Not Ranked
    • Joined on 02-16-2007
    • Posts 4

    Re: problem with crc

    I think you can solve this problem in such way:
    save CRC32 as uint (you've got some WriteLeUint functions inside ZipLib),
    read them in such way:
    uint crc2 = this.IntAsUint(inputBuffer.ReadLeInt());
    where
    private uint IntAsUint(int i)
    {
        return (uint)((0x80000000 & i) | (i & 0x7FFFFFFF));
    }

    this function converts int32->uint32 without using .NET convetions. That's something like C++: UINT ui = *((UINT*)&i))
  • 02-19-2007 3:12 PM In reply to

    Re: problem with crc

    You have to compile SharpZipLib with integer overflow checking disabled.
    Daniel Grunwald
  • 02-23-2007 10:04 PM In reply to

    Re: problem with crc

    I had the same problem in the ZipInputStream.cs and ZipOutputStream.cs CRC's. 

    In the ZipInputStream public ZipEntry GetNextEntry() I added

    if ((flags & 8) == 0) {    entry.Crc = crc2 & 0xFFFFFFFFL;
       entry.Size = size & 0xFFFFFFFFL;
       entry.CompressedSize = csize & 0xFFFFFFFFL;
       int checkVal = (crc2 >> 24);
       if (checkVal < 0) checkVal = byte.MaxValue + 1 + checkVal; // this line
       entry.CryptoCheckValue = Convert.ToByte(checkVal); ;

    and in the ZipOutputStream.cs public void CloseEntry()  I added

    // Patch the header if possible
    if (patchEntryHeader == true) {
        patchEntryHeader =
    false;
        long curPos = baseOutputStream.Position;
        baseOutputStream.Seek(crcPatchPos,
    SeekOrigin.Begin);
        int crcInteger = (int) (curEntry.Crc & int.MaxValue); // this line
        WriteLeInt(crcInteger);

    The trick here is to force the CRC into the integer type that is required by 2s complement logic or using a logical AND (&) to lop off the extra bits. 

    I hope this helps.

    Christopher Zahrobsky
    Reporting Developer / Analyst
    Glenwood Capital Investments, LLC
    czahrobsky@maninvestments.com
Page 1 of 1 (5 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.