{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/11161","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/11161/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/11161/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/11161/events","html_url":"https://github.com/dotnet/corefx/issues/11161","id":173316640,"number":11161,"title":"ZipEntry returns truncated stream on .NET Core (data loss)","user":{"login":"qmfrederik","id":9918129,"avatar_url":"https://avatars.githubusercontent.com/u/9918129?v=3","gravatar_id":"","url":"https://api.github.com/users/qmfrederik","html_url":"https://github.com/qmfrederik","followers_url":"https://api.github.com/users/qmfrederik/followers","following_url":"https://api.github.com/users/qmfrederik/following{/other_user}","gists_url":"https://api.github.com/users/qmfrederik/gists{/gist_id}","starred_url":"https://api.github.com/users/qmfrederik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qmfrederik/subscriptions","organizations_url":"https://api.github.com/users/qmfrederik/orgs","repos_url":"https://api.github.com/users/qmfrederik/repos","events_url":"https://api.github.com/users/qmfrederik/events{/privacy}","received_events_url":"https://api.github.com/users/qmfrederik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"ianhays","id":2606879,"avatar_url":"https://avatars.githubusercontent.com/u/2606879?v=3","gravatar_id":"","url":"https://api.github.com/users/ianhays","html_url":"https://github.com/ianhays","followers_url":"https://api.github.com/users/ianhays/followers","following_url":"https://api.github.com/users/ianhays/following{/other_user}","gists_url":"https://api.github.com/users/ianhays/gists{/gist_id}","starred_url":"https://api.github.com/users/ianhays/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ianhays/subscriptions","organizations_url":"https://api.github.com/users/ianhays/orgs","repos_url":"https://api.github.com/users/ianhays/repos","events_url":"https://api.github.com/users/ianhays/events{/privacy}","received_events_url":"https://api.github.com/users/ianhays/received_events","type":"User","site_admin":false},"assignees":[{"login":"ianhays","id":2606879,"avatar_url":"https://avatars.githubusercontent.com/u/2606879?v=3","gravatar_id":"","url":"https://api.github.com/users/ianhays","html_url":"https://github.com/ianhays","followers_url":"https://api.github.com/users/ianhays/followers","following_url":"https://api.github.com/users/ianhays/following{/other_user}","gists_url":"https://api.github.com/users/ianhays/gists{/gist_id}","starred_url":"https://api.github.com/users/ianhays/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ianhays/subscriptions","organizations_url":"https://api.github.com/users/ianhays/orgs","repos_url":"https://api.github.com/users/ianhays/repos","events_url":"https://api.github.com/users/ianhays/events{/privacy}","received_events_url":"https://api.github.com/users/ianhays/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2016-08-25T21:38:19Z","updated_at":"2016-08-29T10:16:00Z","closed_at":null,"body":"The attached `.zip` file contains a single entry which gets truncated when opened in update mode. The `.zip` file was originally an `.ipa` file (iOS application), and was generated with the Apple toolchain.\r\n\r\nThe entry reports a size of 246000, but the stream which represents the entry has a length of 245760 bytes, resulting in 1240 (`0xF0`) bytes missing.\r\n\r\nThis snippet contains the code which was used to open the zip entry:\r\n\r\n```\r\nusing (Stream stream = File.Open(\"data-write.zip\", FileMode.Open, FileAccess.ReadWrite))\r\nusing (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Update))\r\n{\r\n    var entry = archive.GetEntry(\"A/B/C/D\");\r\n    var size = entry.Length;\r\n\r\n    using (Stream entryStream = entry.Open())\r\n    {\r\n        Assert.Equal(size, entryStream.Length);\r\n    }\r\n}\r\n```\r\n\r\nAfter this snippet executes, .NET Core will update the `.zip` file and the incorrect size data will be written to disk - effectively resulting in data loss.\r\n\r\nThe code behaves as expected on .NET 4.6.1. \r\n\r\n```\r\ndotnet test -f netstandardapp10\r\n(...)\r\n=== TEST EXECUTION SUMMARY ===\r\n   compression-bug  Total: 1, Errors: 0, Failed: 1, Skipped: 0, Time: 0.135s\r\n\r\ndotnet test -f net461\r\n(...)\r\n=== TEST EXECUTION SUMMARY ===\r\n   compression-bug  Total: 1, Errors: 0, Failed: 0, Skipped: 0, Time: 0.134s\r\n```\r\n\r\nI've tried with a couple of zip utilities. They all extract the correct data (same behavior as .NET 4.6.1). Furthermore, the CRC32 data matches the data returned by .NET 4.6.1.\r\n\r\nWhile investigating the issue, I also noticed that `ZipEntry` does not expose the CRC32 field and does not use the CRC32 checksum to validate the data being read. This may have helped me catch the issue earlier.\r\n\r\n(I tried to debug but couldn't get the debugger working, #11087)\r\n\r\n__Repro files__\r\n* .zip file which is not being read correctly by .NET Core: [data.zip](https://github.com/dotnet/corefx/files/438096/data.zip)\r\n* Code used to reproduce the issue: [Program.zip](https://github.com/dotnet/corefx/files/438097/Program.zip)\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/243086915","html_url":"https://github.com/dotnet/corefx/issues/11161#issuecomment-243086915","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/11161","id":243086915,"user":{"login":"qmfrederik","id":9918129,"avatar_url":"https://avatars.githubusercontent.com/u/9918129?v=3","gravatar_id":"","url":"https://api.github.com/users/qmfrederik","html_url":"https://github.com/qmfrederik","followers_url":"https://api.github.com/users/qmfrederik/followers","following_url":"https://api.github.com/users/qmfrederik/following{/other_user}","gists_url":"https://api.github.com/users/qmfrederik/gists{/gist_id}","starred_url":"https://api.github.com/users/qmfrederik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qmfrederik/subscriptions","organizations_url":"https://api.github.com/users/qmfrederik/orgs","repos_url":"https://api.github.com/users/qmfrederik/repos","events_url":"https://api.github.com/users/qmfrederik/events{/privacy}","received_events_url":"https://api.github.com/users/qmfrederik/received_events","type":"User","site_admin":false},"created_at":"2016-08-29T10:16:00Z","updated_at":"2016-08-29T10:16:00Z","body":"@ianhays Thanks for looking into this. Since you've mentioned that it seems to be related to the usage of zlib, and because [zlib includes a sample .zip utility](http://www.zlib.net/zlib_faq.html#faq11), I gave it a shot and tried to extract the file using zlib's `miniunz` (on Linux):\r\n\r\n```\r\nwget http://zlib.net/zlib-1.2.8.tar.gz\r\ntar -xvzf zlib-1.2.8.tar.gz\r\ncd zlib-1.2.8/\r\n./configure \r\nmake\r\ncd contrib/minizip\r\nmake\r\nwget https://github.com/dotnet/corefx/files/438096/data.zip\r\n./miniunz -e data.zip\r\n``` \r\n\r\nand when inspecting the size of the extracted file:\r\n\r\n```\r\n$ ls -l D\r\n-rw-rw-r-- 1 qmfrederik qmfrederik 246000 Dec  7  2015 D\r\n```\r\n\r\nSo it appears zlib's `miniunz` utility is capable of using the zlib deflate stream and extracting the file correctly."}}
{"actor":{"display_login":"qmfrederik"}}