Why does BCL GZipStream (with StreamReader) not reliably detect Data Errors with CRC32?

后端 未结 1 1643
遇见更好的自我
遇见更好的自我 2020-12-01 15:23

The the other day I ran into the question GZipStream doesn't detect corrupt data (even CRC32 passes)? (Of which this might very well be a \"duplicate\", I have mixed fee

相关标签:
1条回答
  • 2020-12-01 15:37

    Preface

    .NET [4 and previous] users should not use the Microsoft-provided GZipStream or DeflateStream classes under any circumstances, unless Microsoft replaces them completely with something that works. Use the DotNetZip library instead.

    Update to Preface

    The .NET Framework 4.5 and later have fixed the compression problem, and GZipStream and DeflateStream use zlib in those versions. I do not know if the CRC problem referenced below has been fixed.

    Another Update

    The CRC bug is not only not fixed, but Microsoft has decided that they won't fix it!

     

    My response in Why does my C# gzip produce a larger file than Fiddler or PHP? shows that this behavior does not reflect a proper implementation of gzip corruption detection. In all of the cases tested, the error would be detected by a proper implementation. (That response also notes why seven of the cases result in good data.)

    Another question is: how does this "compression" method produce 174 bytes of output from a 94-byte string? Especially seeing as how the string is compressible -- gzip reduces it to 84-bytes, even with the overhead of an 18-byte header and trailer. Can you provide a hex dump of that 174 bytes?

    0 讨论(0)
提交回复
热议问题