SharpDevelop Community

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

Fix for problem reading data BZip2 compressed with an old version of SharpZipLib

Last post 10-05-2008 9:41 PM by JohnReilly. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 09-04-2008 9:46 PM

    Fix for problem reading data BZip2 compressed with an old version of SharpZipLib

    I've just tried to upgrade to the newest version from 0.5 and was having  problems reading my old data.

     After hunting around I found an old bug report here (http://bugtracker.sharpdevelop.net/issue/ViewIssue.aspx?id=332&PROJID=2) that describes the exact same thing in 2005, but the bug report was never resolved.

    After decompiling my old version of the library, I found that somewhere between 0.5 and the current version 2 bytes were added to the header - the static text "BZ" prior to the "h".  These extra two bytes were being read in "Initialize" in BZip2InputStream

     I wasn't sure as to the preferred method to submit patches, so here is a fix that will allow it to read both old and new data - modify the initialize method of BZip2InputStream as follows:

     

    void Initialize()
            {
                char magic1 = BsGetUChar();
                char magic2 = BsGetUChar();

                // special code for old version headers (looks like 0.5.0 or so)
                if (magic1 != 'B' || magic2 != 'Z')
                {
                    if ((magic1 == 'h') && (magic2>='1'&&magic2<='9'))
                    {
                        SetDecompressStructureSizes(magic2 - '0');
                        computedCombinedCRC = 0;
                        return;
                    }
                }

                char magic3 = BsGetUChar();
                char magic4 = BsGetUChar();
               
                if (magic1 != 'B' || magic2 != 'Z' || magic3 != 'h' || magic4 < '1' || magic4 > '9') {
                    streamEnd = true;
                    return;
                }
               
                SetDecompressStructureSizes(magic4 - '0');
                computedCombinedCRC = 0;
            }

  • 10-05-2008 9:41 PM In reply to

    Re: Fix for problem reading data BZip2 compressed with an old version of SharpZipLib

    Good work!

    Thanks for that.

Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.