-
Notifications
You must be signed in to change notification settings - Fork 6.1k
docs: Breaking change – CRC32 validation added when reading ZIP archive entries (.NET 11 Preview 3) #52855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
docs: Breaking change – CRC32 validation added when reading ZIP archive entries (.NET 11 Preview 3) #52855
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,66 @@ | ||||||||
| --- | ||||||||
| title: "Breaking change: CRC32 validation added when reading ZIP archive entries" | ||||||||
| description: "Learn about the breaking change in .NET 11 where reading ZIP archive entries now validates CRC32 checksums and throws InvalidDataException for corrupted data." | ||||||||
| ms.date: 04/03/2026 | ||||||||
| ai-usage: ai-assisted | ||||||||
| --- | ||||||||
|
|
||||||||
| # CRC32 validation added when reading ZIP archive entries | ||||||||
|
|
||||||||
| Starting in .NET 11, the <xref:System.IO.Compression> library validates CRC32 checksums when reading ZIP archive entries. If the computed CRC32 checksum doesn't match the expected value stored in the ZIP file's metadata, an <xref:System.IO.InvalidDataException> is thrown. | ||||||||
|
|
||||||||
| ## Version introduced | ||||||||
|
|
||||||||
| .NET 11 Preview 3 | ||||||||
|
|
||||||||
| ## Previous behavior | ||||||||
|
|
||||||||
| Previously, `System.IO.Compression` didn't validate CRC32 checksums when reading ZIP archive entries. Corrupted or tampered ZIP entries could be read without errors, potentially causing silent data corruption. | ||||||||
|
|
||||||||
| ```csharp | ||||||||
| using System.IO.Compression; | ||||||||
|
|
||||||||
| using var archive = ZipFile.OpenRead("corrupted.zip"); | ||||||||
| var entry = archive.GetEntry("file.txt"); | ||||||||
| using var stream = entry.Open(); | ||||||||
|
|
||||||||
| // Data could be read without any validation of its integrity. | ||||||||
| byte[] buffer = new byte[entry.Length]; | ||||||||
| stream.Read(buffer, 0, buffer.Length); | ||||||||
|
||||||||
| ``` | ||||||||
gewarren marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
|
||||||||
| ## New behavior | ||||||||
|
|
||||||||
| Starting in .NET 11, the library verifies the integrity of ZIP entries during read operations. If the computed CRC32 checksum doesn't match the expected value from the ZIP file's metadata, an <xref:System.IO.InvalidDataException> is thrown. | ||||||||
|
|
||||||||
| ## Type of breaking change | ||||||||
|
|
||||||||
| This change is a [behavioral change](../../categories.md#behavioral-change). | ||||||||
|
|
||||||||
| ## Reason for change | ||||||||
|
|
||||||||
| This change improves the reliability and security of `System.IO.Compression`. By validating CRC32 checksums, the library detects and prevents use of corrupted or tampered ZIP entries, ensuring applications don't inadvertently process invalid data. For more information, see [dotnet/runtime#124766](https://github.com/dotnet/runtime/pull/124766). | ||||||||
|
|
||||||||
| ## Recommended action | ||||||||
|
|
||||||||
| If your application processes ZIP files that might be corrupted or tampered with, handle <xref:System.IO.InvalidDataException> appropriately: | ||||||||
|
|
||||||||
| ```csharp | ||||||||
| try | ||||||||
| { | ||||||||
| using var archive = ZipFile.OpenRead("example.zip"); | ||||||||
| var entry = archive.GetEntry("file.txt"); | ||||||||
|
||||||||
| var entry = archive.GetEntry("file.txt"); | |
| var entry = archive.GetEntry("file.txt") | |
| ?? throw new InvalidOperationException("The ZIP archive doesn't contain 'file.txt'."); |
Outdated
Copilot
AI
Apr 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the recommended action sample, new byte[entry.Length] doesn't compile because ZipArchiveEntry.Length is long. Use a fixed-size buffer (or a safe conversion) instead of sizing the array from entry.Length.
Uh oh!
There was an error while loading. Please reload this page.