Skip to content

Commit 83b0e0f

Browse files
authored
ZipArchiveEntry encoding breaking change (#42475)
1 parent fe96781 commit 83b0e0f

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

docs/core/compatibility/9.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ If you're migrating an app to .NET 9, the breaking changes listed here might aff
4242
| [InMemoryDirectoryInfo prepends rootDir to files](core-libraries/9.0/inmemorydirinfo-prepends-rootdir.md) | Behavioral change | Preview 1 |
4343
| [RuntimeHelpers.GetSubArray returns different type](core-libraries/9.0/getsubarray-return.md) | Behavioral change | Preview 1 |
4444
| [Support for empty environment variables](core-libraries/9.0/empty-env-variable.md) | Behavioral change | Preview 6 |
45+
| [ZipArchiveEntry names and comments respect UTF8 flag](core-libraries/9.0/ziparchiveentry-encoding.md) | Behavioral change | RC 1 |
4546

4647
## Cryptography
4748

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: "ZipArchiveEntry names and comments respect UTF8 flag"
3+
description: Learn about the .NET 9 breaking change in core .NET libraries where ZipArchiveEntry names and comments now respect the UTF8 flag when decoding.
4+
ms.date: 09/04/2024
5+
---
6+
# ZipArchiveEntry names and comments respect UTF8 flag
7+
8+
A <xref:System.IO.Compression.ZipArchive> can be created with an <xref:System.Text.Encoding> parameter, which is used to decode the names and comments of entries in the ZIP archive. .NET 7 introduced a regression where this encoding was used by default, with a fallback to the system default code page (UTF8 in .NET Core) if no encoding was supplied. This regression is corrected in .NET 9: if the entry's general purpose bit flags indicate that UTF8 should be used, that is respected. If the UTF8 bit flag is not set, the user-supplied encoding is used (with the existing fallback to the system default code page if none is supplied.)
9+
10+
## Previous behavior
11+
12+
In .NET 7 and .NET 8, if a `ZipArchive` was instantiated with a user-specified `entryNameEncoding` parameter, this encoding was always used when decoding the names and comments of entries in the ZIP archive. `entryNameEncoding` was used even if the entry had the bit set to signify that its name and comment were encoded in UTF8.
13+
14+
## New behavior
15+
16+
Starting in .NET 9, when a ZIP archive entry's name and comment are decoded, its UTF8 bit flag is respected. The user-supplied `entryNameEncoding` parameter is only used to decode the entry's name and comment if this bit flag is unset.
17+
18+
## Version introduced
19+
20+
.NET 9 RC 1
21+
22+
## Type of breaking change
23+
24+
This change is a [behavioral change](../../categories.md#behavioral-change).
25+
26+
## Reason for change
27+
28+
This change corrects a regression in .NET 7 and .NET 8. It also returns <xref:System.IO.Compression.ZipArchive> to compliance with the ZIP file format specification, sections 4.4.4 and appendix D.
29+
30+
## Recommended action
31+
32+
If your code passes an encoding to the [ZipArchive constructor](xref:System.IO.Compression.ZipArchive.%23ctor(System.IO.Stream,System.IO.Compression.ZipArchiveMode,System.Boolean,System.Text.Encoding)), be aware that this encoding isn't respected in all situations. It will only be used if the entry's UTF8 bit is not set.
33+
34+
If you're using <xref:System.IO.Compression.ZipArchive> to parse ZIP entries with names encoded in non-UTF8 format (but which have the UTF8 bit flag set), you will no longer be able to do so. The previous behavior was a bug.
35+
36+
## Affected APIs
37+
38+
- <xref:System.IO.Compression.ZipArchive.%23ctor(System.IO.Stream,System.IO.Compression.ZipArchiveMode,System.Boolean,System.Text.Encoding)>
39+
- <xref:System.IO.Compression.ZipFile.ExtractToDirectory(System.IO.Stream,System.String,System.Text.Encoding,System.Boolean)?displayProperty=fullName>
40+
- <xref:System.IO.Compression.ZipFile.ExtractToDirectory(System.String,System.String,System.Text.Encoding,System.Boolean)?displayProperty=fullName>
41+
- <xref:System.IO.Compression.ZipFile.ExtractToDirectory(System.String,System.String,System.Text.Encoding)?displayProperty=fullName>
42+
- <xref:System.IO.Compression.ZipFile.ExtractToDirectory(System.IO.Stream,System.String,System.Text.Encoding)?displayProperty=fullName>
43+
- <xref:System.IO.Compression.ZipFile.Open(System.String,System.IO.Compression.ZipArchiveMode,System.Text.Encoding)?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ items:
4040
href: core-libraries/9.0/getsubarray-return.md
4141
- name: Support for empty environment variables
4242
href: core-libraries/9.0/empty-env-variable.md
43+
- name: ZipArchiveEntry names and comments respect UTF8 flag
44+
href: core-libraries/9.0/ziparchiveentry-encoding.md
4345
- name: Cryptography
4446
items:
4547
- name: SafeEvpPKeyHandle.DuplicateHandle up-refs the handle
@@ -1244,6 +1246,8 @@ items:
12441246
href: core-libraries/9.0/getsubarray-return.md
12451247
- name: Support for empty environment variables
12461248
href: core-libraries/9.0/empty-env-variable.md
1249+
- name: ZipArchiveEntry names and comments respect UTF8 flag
1250+
href: core-libraries/9.0/ziparchiveentry-encoding.md
12471251
- name: .NET 8
12481252
items:
12491253
- name: Activity operation name when null

0 commit comments

Comments
 (0)