1

Closed

Array out of bounds exception in finish()

description

Hi,
 
I'm attempting to replace the built in Gzip with this library for a WCF project I'm working on now.The code in question is derived entirely from the WCF compression sample which can be found here: http://msdn.microsoft.com/en-us/library/ms751458.aspx.
 
In the sample project, just replace the System.IO.Compression (which works) with Ionic.Zlib and you should see it throw an exception when decompressing a Gzipped stream. I've debugged using source and can trace it to the finish() method (in ZlibBaseStream.cs - called by Dispose).
 
// workitem 8679
if (_z.AvailableBytesIn !=8)
// do an array copy of length _z.AvailableBytesIn
 
The problem is that in the aforementioned WCF sample, the _z.AvailableBytesIn is larger than 8 bytes. This causes an ArgumentException because the array you are trying to copy into (trailer) is only 8 bytes. I believe this is due to the way the WCF sample does buffered reads.
 
Anyway, I've attached a patch which simply changes the if statement to check for _z.AvailableBytesIn < 8. That fixed my issue and BTW I get much better compression ratios with this library than the built in System.IO.Compression. Thanks!

file attachments

Closed Jun 22, 2011 at 1:11 AM by Cheeso
Fixed in changeset 79583. The first release to contain this fix will be v1.9.1.6

comments

bschloz wrote Nov 23, 2010 at 5:29 PM

Found another post which fixes the sample to properly calculate and write the compressed bytes to the buffer manager. This fixes the aforementioned bug and allows me to use the DotNetZip ZLib as released. Here is the post in case anyone is interested: http://geekswithblogs.net/argot/archive/2009/10/27/wcf-message-compression---gzip-7zip.aspx.