{"action":"opened","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/30030","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/30030/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/30030/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/30030/events","html_url":"https://github.com/dotnet/corefx/issues/30030","id":328317935,"node_id":"MDU6SXNzdWUzMjgzMTc5MzU=","number":30030,"title":"BrotliStream decompresser reads misaligned chunks on repetetive data; TryDecompress works","user":{"login":"jhudsoncedaron","id":17086870,"node_id":"MDQ6VXNlcjE3MDg2ODcw","avatar_url":"https://avatars0.githubusercontent.com/u/17086870?v=4","gravatar_id":"","url":"https://api.github.com/users/jhudsoncedaron","html_url":"https://github.com/jhudsoncedaron","followers_url":"https://api.github.com/users/jhudsoncedaron/followers","following_url":"https://api.github.com/users/jhudsoncedaron/following{/other_user}","gists_url":"https://api.github.com/users/jhudsoncedaron/gists{/gist_id}","starred_url":"https://api.github.com/users/jhudsoncedaron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhudsoncedaron/subscriptions","organizations_url":"https://api.github.com/users/jhudsoncedaron/orgs","repos_url":"https://api.github.com/users/jhudsoncedaron/repos","events_url":"https://api.github.com/users/jhudsoncedaron/events{/privacy}","received_events_url":"https://api.github.com/users/jhudsoncedaron/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-31T22:23:01Z","updated_at":"2018-05-31T22:23:01Z","closed_at":null,"author_association":"NONE","body":"I've got a large data blob (that unfortunately I can only provide under an NDA) that reliably causes BrotliStream to read misaligned chunks or drop chunks. \r\n\r\nHere is the test code. It raises \"BrotliStream chunk trouble; bytes are the same but the stream isn't.\" at the same place every time.\r\n\r\n    using System;\r\n    using System.IO;\r\n\r\n    namespace brotlitrouble\r\n    {\r\n        class Program\r\n        {\r\n            static void Main(string[] args)\r\n            {\r\n                var sourceArray = File.ReadAllBytes(\"tablebase.dat\");\r\n                var uclen = sourceArray.Length;\r\n                var m = System.IO.Compression.BrotliEncoder.GetMaxCompressedLength(uclen);\r\n                int size;\r\n                byte[] result;\r\n                result = new byte[m + 8];\r\n                if (!System.IO.Compression.BrotliEncoder.TryCompress(sourceArray, result.AsSpan(8, m - 8), out size))\r\n                    throw new Exception(\"BrotliEncoder.TryCompress was given enough memory; why did it fail?\");\r\n                // Diagnostic check; this one passes\r\n                var check = new byte[sourceArray.Length];\r\n                if (!System.IO.Compression.BrotliDecoder.TryDecompress(result.AsSpan(8, m - 8), check, out int writecheck)\r\n                    || !ByteArrayEquals(sourceArray, 0, sourceArray.Length, check, 0, check.Length))\r\n                    throw new Exception(\"BrotliDecoder.TryDecompress did not invert BrotliEncoder.TryCompress\");\r\n                // Diagnostic check; this one fails\r\n                var mbc = new MemoryStream(result);\r\n                mbc.Position = 8;\r\n                using (var saa = new StreamReader(new System.IO.Compression.BrotliStream(mbc, System.IO.Compression.CompressionMode.Decompress)))\r\n                using (var sbb = new StreamReader(new MemoryStream(sourceArray)))\r\n                {\r\n                    for (; ; )\r\n                    {\r\n                        var linea = saa.ReadLine();\r\n                        var lineb = sbb.ReadLine();\r\n                        if (linea != lineb)\r\n                            throw new Exception(\"BrotliStream chunk trouble; bytes are the same but the stream isn't.\" + Environment.NewLine + linea.Trim() + Environment.NewLine + lineb.Trim());\r\n                        if (linea is null) break;\r\n                    }\r\n                }\r\n            }\r\n\r\n            static bool ByteArrayEquals(byte[] s, int sstart, int slen, byte[] t, int tstart, int tlen)\r\n            {\r\n                if (slen != tlen) return false;\r\n                for (int i = 0; i < slen; i++)\r\n                    if (s[sstart + i] != t[tstart + i])\r\n                        return false;\r\n                return true;\r\n            }\r\n        }\r\n    }\r\n\r\nApologies, but \"tablebase.dat\" contains non-public data that I cannot pass out to everyone."}}
{"actor":{"display_login":"jhudsoncedaron"}}