This project is read-only.

decompress bytearray

Jul 7, 2011 at 10:45 PM
Edited Jul 7, 2011 at 10:47 PM

I receive from server compressed deflate bytes, when i want to decompress my byte array i receive the Exception. This is compress text and it can have a non-ansi character.

$exception    {Ionic.Zlib.ZlibException: Bad state (invalid stored block lengths)
   at Ionic.Zlib.InflateManager.Inflate(FlushType flush) in c:\DotNetZip\v1.9.1.5\DotNetZip\Zlib\Inflate.cs:line 1690
   at Ionic.Zlib.ZlibCodec.Inflate(FlushType flush) in c:\DotNetZip\v1.9.1.5\DotNetZip\Zlib\ZlibCodec.cs:line 358
   at Ionic.Zlib.ZlibBaseStream.Read(Byte[] buffer, Int32 offset, Int32 count) in c:\DotNetZip\v1.9.1.5\DotNetZip\Zlib\ZlibBaseStream.cs:line 477
   at Ionic.Zlib.DeflateStream.Read(Byte[] buffer, Int32 offset, Int32 count) in c:\DotNetZip\v1.9.1.5\DotNetZip\Zlib\DeflateStream.cs:line 534
   at Ionic.Zlib.ZlibBaseStream.UncompressBuffer(Byte[] compressed, Stream decompressor) in c:\DotNetZip\v1.9.1.5\DotNetZip\Zlib\ZlibBaseStream.cs:line 615
   at Ionic.Zlib.DeflateStream.UncompressBuffer(Byte[] compressed) in c:\DotNetZip\v1.9.1.5\DotNetZip\Zlib\DeflateStream.cs:line 698
   at Gadulec.Net.PacketTask.FriedRecive() in C:\Users\Johniak\Documents\Visual Studio 2010\Projects\Gadulec. Net\Gadulec. Net\Packet.cs:line 316}    System.Exception {Ionic.Zlib.ZlibException}


                reply = new byte[size - 7];
                for (int i = 0; i < (size - 7); i++)
                    reply[i] = Receiver.ReadByte();
                var buffer = Ionic.Zlib.DeflateStream.UncompressBuffer(reply);

Sory for my English

Jul 12, 2011 at 7:45 PM

1st - try v1.9.1.6000 of DotNetZip. See if the problem still occurs there.

2nd - If not, then.... Do you know what the original uncompressed data is?   Do you know how it was compressed, using what tool or library?   Which is it?

Can you produce a test case that reliably reproduces this problem? can you provide code to me me that generates compressed data, then tries decompressing in the way you describe, using DotNetZip, and causes the exception you see?

It's possible to see the error you're describing when decompressing data that is not a valid compressed stream, or not a valid DEFLATE stream.  For example if you compress with ZLIB then try decompressing with DeflateStream, you may see this problem.  Or vice versa. So please verify that the data you are decompressing is actually a DEFLATE stream.