@@ -493,6 +493,14 @@ private int ReadingNotSupported(byte[] destination, int offset, int count)
493493 throw new ZipException ( "The compression method for this entry is not supported" ) ;
494494 }
495495
496+ /// <summary>
497+ /// Handle attempts to read from this entry by throwing an exception
498+ /// </summary>
499+ private int StoredDescriptorEntry ( byte [ ] destination , int offset , int count ) =>
500+ throw new StreamUnsupportedException (
501+ "The combination of Stored compression method and Descriptor flag is not possible to read using ZipInputStream" ) ;
502+
503+
496504 /// <summary>
497505 /// Perform the initial read on an entry which may include
498506 /// reading encryption headers and setting up inflation.
@@ -544,13 +552,22 @@ private int InitialRead(byte[] destination, int offset, int count)
544552 inputBuffer . CryptoTransform = null ;
545553 }
546554
547- if ( ( csize > 0 ) || ( ( flags & ( int ) GeneralBitFlags . Descriptor ) != 0 ) )
555+ var usesDescriptor = ( flags & ( int ) GeneralBitFlags . Descriptor ) != 0 ;
556+
557+ if ( ( csize > 0 ) || usesDescriptor )
548558 {
549559 if ( ( method == CompressionMethod . Deflated ) && ( inputBuffer . Available > 0 ) )
550560 {
551561 inputBuffer . SetInflaterInput ( inf ) ;
552562 }
553563
564+ // It's not possible to know how many bytes to read when using "Stored" compression (unless using encryption)
565+ if ( ! entry . IsCrypted && method == CompressionMethod . Stored && usesDescriptor )
566+ {
567+ internalReader = StoredDescriptorEntry ;
568+ return StoredDescriptorEntry ( destination , offset , count ) ;
569+ }
570+
554571 internalReader = new ReadDataHandler ( BodyRead ) ;
555572 return BodyRead ( destination , offset , count ) ;
556573 }
0 commit comments