@@ -77,7 +77,7 @@ internal ZipArchiveEntry(ZipArchive archive, ZipCentralDirectoryFileHeader cd)
7777 _outstandingWriteStream = null ;
7878
7979 _storedEntryNameBytes = cd . Filename ;
80- _storedEntryName = ( _archive . EntryNameAndCommentEncoding ?? Encoding . UTF8 ) . GetString ( _storedEntryNameBytes ) ;
80+ _storedEntryName = DecodeEntryString ( _storedEntryNameBytes ) ;
8181 DetectEntryNameVersion ( ) ;
8282
8383 _lhUnknownExtraFields = null ;
@@ -200,7 +200,7 @@ public int ExternalAttributes
200200 [ AllowNull ]
201201 public string Comment
202202 {
203- get => ( _archive . EntryNameAndCommentEncoding ?? Encoding . UTF8 ) . GetString ( _fileComment ) ;
203+ get => DecodeEntryString ( _fileComment ) ;
204204 set
205205 {
206206 _fileComment = ZipHelper . GetEncodedTruncatedBytesFromString ( value , _archive . EntryNameAndCommentEncoding , ushort . MaxValue , out bool isUTF8 ) ;
@@ -352,6 +352,18 @@ public override string ToString()
352352 return FullName ;
353353 }
354354
355+ private string DecodeEntryString ( byte [ ] entryStringBytes )
356+ {
357+ Debug . Assert ( entryStringBytes != null ) ;
358+
359+ Encoding readEntryStringEncoding =
360+ ( _generalPurposeBitFlag & BitFlagValues . UnicodeFileNameAndComment ) == BitFlagValues . UnicodeFileNameAndComment
361+ ? Encoding . UTF8
362+ : _archive ? . EntryNameAndCommentEncoding ?? Encoding . UTF8 ;
363+
364+ return readEntryStringEncoding . GetString ( entryStringBytes ) ;
365+ }
366+
355367 // Only allow opening ZipArchives with large ZipArchiveEntries in update mode when running in a 64-bit process.
356368 // This is for compatibility with old behavior that threw an exception for all process bitnesses, because this
357369 // will not work in a 32-bit process.
0 commit comments