{
  "WorkItem": {
    "AffectedComponent": {
      "Name": "",
      "DisplayName": ""
    },
    "ClosedComment": "no response",
    "ClosedDate": "2009-10-30T15:48:45.063-07:00",
    "CommentCount": 0,
    "Custom": null,
    "Description": "Hi,\n \nI am attempting to compress and then decompress some byte arrays using the newest (beta) version of libraries.  I am using the DeflateStream.  I had this working in version 1.8 of the library, but upgraded to 1.9 (had some weird issues, possibly unrelated to this library, but I figured it couldn't hurt to try something new).  There seems to be a bug that occurs when using the Read() function of the DeflateStream when I am decompressing.  I have the following code:\n \n                int compressedLength;\n                byte[] bufferedBytes;\n \n                MemoryStream memoryStream = new MemoryStream(buffer.Array, buffer.Offset, buffer.Count);\n                DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Decompress, true);\n                MemoryStream uncompressedStream = new MemoryStream();\n                \n                int readBytes = 0;\n                bufferedBytes = new byte[1024];\n                while ((readBytes = deflateStream.Read(bufferedBytes, 0, bufferedBytes.Length)) > 0)\n                    uncompressedStream.Write(bufferedBytes, 0, readBytes);\n \n \n \n \nAs you can see, I am attempting to loop by 1024 byte increments and decompress an array of bytes (buffer.Array is a byte[]).  The bug seems to manifest when the decompressed size of the byte array is smaller than 1024.  So, if the input is maybe 293 bytes compressed, and would be maybe 417 bytes uncompressed, the Read() function returns 0 as the number of bytes read.  But not always the case, ie, many times it works correctly and returns the number of bytes read even if it is less than 1024.  But I can consistently reproduce this with the 293 bytes compressed to 417 bytes uncompressed.  The interesting thing is that the DeflateStream correctly decompresses it, that is to say, after calling Read(), I can see that the DeflateStream.TotalIn is 293 and the DeflateStream.TotalOut is 417...  But since the Read() returned 0, nothing ends up being written to the \"uncompressedStream\" variable, even though \"bufferedBytes\" actually contains the correct data.\n \nI am pretty sure that this is not the desired behavior, and has caused me some issues.  I have found a workaround, which is to make my \"bufferedBytes\" array be of size Math.Min(1024, buffer.Count) instead of 1024.  This basically eliminates cases where the size of \"bufferedBytes\" is greater than the decompressed byte array returned by Read().  But I shouldn't have to do this.  The updated line of code is:         \n \n               bufferedBytes = new byte[Math.Min(1024, buffer.Count)];\n \n \n \n \nAny help would be appreciated.",
    "LastUpdatedDate": "2013-05-16T05:32:06.507-07:00",
    "PlannedForRelease": "",
    "ReleaseVisibleToPublic": false,
    "Priority": {
      "Name": "Low",
      "Severity": 50,
      "Id": 1
    },
    "ProjectName": "DotNetZip",
    "ReportedDate": "2009-09-28T23:39:33.813-07:00",
    "Status": {
      "Name": "Closed",
      "Id": 4
    },
    "ReasonClosed": {
      "Name": "Unassigned"
    },
    "Summary": "Incorrect Value Returned by DeflateStream.Read()",
    "Type": {
      "Name": "Issue",
      "Id": 3
    },
    "VoteCount": 1,
    "Id": 8869
  },
  "FileAttachments": [
    {
      "FileId": 2446,
      "FileName": "x.txt",
      "DownloadUrl": ".\\2446"
    },
    {
      "FileId": 2447,
      "FileName": "x.txt",
      "DownloadUrl": ".\\2447"
    }
  ],
  "Comments": [
    {
      "Message": "I cannot reproduce this problem .\r\n",
      "PostedDate": "2009-09-29T05:45:02.793-07:00",
      "Id": -2147483648
    },
    {
      "Message": "Are you still following this workitem?  \r\nCan you provide source code that reproduces the problem? \r\nIf you can't , I'm going to close this as non-reproducable. \r\nIf you don't get back to me within a day or two, I'll close it. ",
      "PostedDate": "2009-10-28T01:24:35.487-07:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2009-10-30T15:48:45.063-07:00",
      "Id": -2147483648
    },
    {
      "Message": "I have the same problem, but not always.\r\nI changed the buffersize from 1024 to 1 (byte). \r\nThe microsoft decompression (System.Compression) had the same problem (?)\r\n\r\nI use the following code in a SoapExtension.\r\nThe instream is useally of type   \"System.Net.ConnectStream\"\r\n\r\n\r\n        public static void Decompress(Stream inStream, MemoryStream outStream)\r\n        {\r\n            using (DeflateStream Decompressor = new DeflateStream(inStream\r\n                , CompressionMode.Decompress\r\n                , CompressionLevel.Default\r\n                , true))\r\n            {\r\n                byte[] MyBytes = new byte[1];\r\n                int BytesRead = Decompressor.Read(MyBytes, 0, 1);\r\n                while (BytesRead != 0)\r\n                {\r\n                    outStream.WriteByte(MyBytes[0]);\r\n                    BytesRead = Decompressor.Read(MyBytes, 0, 1);\r\n                }\r\n            }\r\n        }\r\n\r\n\r\nThis is the compressor:\r\n\r\n        public static void Compress(MemoryStream inStream, Stream outStream)\r\n        {\r\n            using (DeflateStream Compressor = new DeflateStream(outStream\r\n                , CompressionMode.Compress\r\n                , CompressionLevel.Default\r\n                , true))\r\n            {\r\n                inStream.Seek(0, SeekOrigin.Begin);\r\n                byte[] Buffer = new byte[1024];\r\n                int BytesRead = inStream.Read(Buffer, 0, Buffer.Length);\r\n                while (BytesRead != 0)\r\n                {\r\n                    Compressor.Write(Buffer, 0, BytesRead);\r\n                    BytesRead = inStream.Read(Buffer, 0, Buffer.Length);\r\n                }\r\n            }\r\n        }\r\n\r\n\r\nThe attached file has the data that causes the trouble. \r\nThe filesize is 408 bytes, the actual data is 407 bytes.\r\nI used System.IO.File.WriteAllBytes()\r\n\r\n",
      "PostedDate": "2009-11-26T13:30:00.95-08:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2009-11-26T13:30:06.02-08:00",
      "Id": -2147483648
    },
    {
      "Message": "I forgot to send the test code. It fail's in the decompress    ;)\r\n\r\n            byte[] AllBytes = System.IO.File.ReadAllBytes(@\"D:\\Temp\\x.txt\");\r\n            System.IO.MemoryStream MC = new System.IO.MemoryStream();\r\n            VrumunSoapExtension.CCompress.Compress(new System.IO.MemoryStream(AllBytes), MC);\r\n\r\n            MC.Seek(0, System.IO.SeekOrigin.Begin);\r\n\r\n            System.IO.MemoryStream MD = new System.IO.MemoryStream();\r\n            VrumunSoapExtension.CDecompress.Decompress(MC, MD);\r\n            MD.Seek(0, System.IO.SeekOrigin.Begin);\r\n\r\n\r\n\r\n    public class CCompress\r\n    {\r\n        public static void Compress(MemoryStream inStream, Stream outStream)\r\n        {\r\n            using (DeflateStream Compressor = new DeflateStream(outStream\r\n                , CompressionMode.Compress\r\n                , CompressionLevel.Default\r\n                , true))\r\n            {\r\n                inStream.Seek(0, SeekOrigin.Begin);\r\n                byte[] Buffer = new byte[1024];\r\n                int n;\r\n                while ((n = inStream.Read(Buffer, 0, Buffer.Length)) != 0)\r\n                {\r\n                    Compressor.Write(Buffer, 0, n);\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n\r\n    public class CDecompress\r\n    {\r\n        public static void Decompress(Stream inStream, MemoryStream outStream)\r\n        {\r\n            using (DeflateStream Decompressor = new DeflateStream(inStream\r\n                , CompressionMode.Decompress\r\n                , CompressionLevel.Default\r\n                , true))\r\n            {\r\n                byte[] MyBytes = new byte[1024];\r\n                int BytesRead = Decompressor.Read(MyBytes, 0, 1024);\r\n                while (BytesRead != 0)\r\n                {\r\n                    outStream.WriteByte(MyBytes[0]);\r\n                    BytesRead = Decompressor.Read(MyBytes, 0, 1024);\r\n                }\r\n            }\r\n        }\r\n    }",
      "PostedDate": "2009-11-26T13:48:56.043-08:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2009-11-26T13:48:59.873-08:00",
      "Id": -2147483648
    },
    {
      "Message": "i get this as well, and i know what it is.\r\nas far as i see, the DeflateStream sometimes (depending on what it's compressing) returns 0 bytes although it is not finished with the stream...\r\nthe read size closes the stream since it got read == 0.\r\ni solved this by using the drop replace DeflateStream from Ionic.Zlib.DeflateStream free on codeplex.\r\nit's a real bug as far as i know.",
      "PostedDate": "2010-06-20T07:13:53.777-07:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2013-02-21T18:43:59.077-08:00",
      "Id": -2147483648
    },
    {
      "Message": "",
      "PostedDate": "2013-05-16T05:32:06.507-07:00",
      "Id": -2147483648
    }
  ]
}