Repository navigation
GZipStream : Enforcing strict validation to detect truncated gzip files [.NET 9] #122572
Replies: 1 comment
|
Yes, this exact scenario was addressed in .NET 8 via PR #75671. It added an opt-in switch to detect truncated streams across To enable it, set the You can enable it in code at startup: AppContext.SetSwitch("System.IO.Compression.UseStrictValidation", true);Or in your project's {
"configProperties": {
"System.IO.Compression.UseStrictValidation": true
}
}Or via environment variable: DOTNET_SYSTEM_IO_COMPRESSION_USESTRICTVALIDATION=1Why it's opt-inBy default, decompression streams in .NET return EOF (0 bytes read) when reaching the end of available input without throwing if the stream ends prematurely. Turning strict validation on by default would have broken applications that rely on reading partially streamed or truncated archives. With |
Uh oh!
There was an error while loading. Please reload this page.
.NET Version : 9.0
I'm working on a way to detect and process gzip files that may get corrupted somewhere in the environment, and was looking at using the .NET library GZipStream as such :
This works fine in most cases, but it doesn't seem as strict as other libraries when it comes to validating truncated files. For example, if I have a gzip file truncated halfway that is generated as such:
then the GZipStream library does not throw any exception, but a command such as
gunzip -tfails due to truncated data. The same can be observed if we generate a GZ file with the last 8 bytes removed (CRC + ISize)Is there a way to enforce strict validation using GZipStream that would be the equivalent of say the command
gunzip -ton unix systems?I saw other discussions around changing the GZipStream API to add strict validation, but it looks like it was later reversed, then put back in .NET8 , but I'm not sure if this covers the same case : #75671
All reactions